AmpersandJS / ampersand-router

Clientside router with fallbacks for browsers that don't support pushState. Mostly lifted from Backbone.js.
MIT License
70 stars 16 forks source link

Underscore dependency #11

Closed jgillich closed 10 years ago

jgillich commented 10 years ago

This issue is not really specific to ampersand-router, but I it seems there is no general place to discuss things that cover multiple ampersand modules.

The thing is, underscore is awesome, I use and love it, but it is also a pretty big dependency that doesn't seem appropriate for a collection-of-tiny-modules type framework. Also, unlike Backbone, you can't easily replace underscore with alternatives like lodash.

There was already a mention in #1 that it is planned to remove the underscore dependency in the router, but it makes sense only if it is removed in other modules as well in my opinion.

As a replacement, I would suggest taking underscore and splitting its functions in separate files, probably removing a few that are provided by the most browsers already (like bind, map etc). So instead of doing this:

var _ = require('underscore');
_.extend(...);

you would have to do this:

var extend = require('ampersand-something/extend');
extend(...);

Thoughts?

kamilogorek commented 10 years ago

How about moving to specific lodash modules? Instead of requireing whole underscore, we could just require necessary functions:

var _ = {
    extend: require('lodash.extend'),
    isRegExp: require('lodash.isregexp'),
    isFunction: require('lodash.isfunction'),
    result: require('lodash.result')
};

or

var _extend = require('lodash.extend');
var _isRegExp = require('lodash.isregexp');
var _isFunction = require('lodash.isfunction');
var _result = require('lodash.result');

or even leverage something like https://github.com/lukekarrys/lodash-replacer.

jgillich commented 10 years ago

The advantage of a single module is that it is easier to install; Browserify does only include the used files so the the end result should be the same.

lodash-replacer looks interesting, but since it requires some effort to configure, most users probably won't use it and end up with the full underscore in their apps.

jgillich commented 10 years ago

lodash-cli looks really interesting, it can be used to generate a modular lodash build that puts each function in its own file and supports CommonJS.

wraithgar commented 10 years ago

We will be tracking the removal of underscore here https://github.com/AmpersandJS/ampersand/issues/36