dropchop icon indicating copy to clipboard operation
dropchop copied to clipboard

Simplify browserify bundles with `require` module

Open nickpeihl opened this issue 8 years ago • 7 comments

I started work over the weekend to require modules within the dropchop source. This would be one of the first steps in removing the dependency on Gulp as we could run browserify as a npm one-liner rather than streaming each module through Gulp.

nickpeihl avatar Aug 01 '16 15:08 nickpeihl

Nice! I started taking a peak at the lift this is going to be .. it's more complex than I hoped, considering everything is written in the dc = dc || {} syntax. Some thoughts around how to initialize each *.dropchop.js's init() function and continue using $(dc).on and $(dc).trigger as the publication/subscription model would be 👍

mapsam avatar Aug 01 '16 16:08 mapsam

Speculating here with some pseudocode. Maybe make each piece modular like

module.exports = function() {
...
return someInitFunction
}

Then in dropchop.js

var map = require('./dropchop.map')
...
dc.map = map()
...

Appreciate input from anyone.

nickpeihl avatar Aug 01 '16 17:08 nickpeihl

@mapsam Is this a hard block on #261 or does it not affect modularization?

wboykinm avatar Aug 02 '16 03:08 wboykinm

@wboykinm I don't think so. You could probably add each of the turf modules to this array instead of the main turf library. It's worth a try since this issue might take a while.

nickpeihl avatar Aug 02 '16 03:08 nickpeihl

Indeed - @nickpeihl's array idea should work just fine for now.

mapsam avatar Aug 02 '16 14:08 mapsam

@mapsam: Do you have any references or links to the type of architecture design used in dropchop? I'm not familiar with this style of application architecture.

nickpeihl avatar Aug 02 '16 22:08 nickpeihl

@nickpeihl all of dropchop is currently written in the "module pattern" (not to be confused with npm modules) and I always find this article super helpful in how to organize code, globals, and share across files: http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html

Introducing require and browserify may or may not require us to re-architect how dropchop is written.

mapsam avatar Aug 03 '16 13:08 mapsam