documentcloud / underscore-contrib

The brass buckles on Underscore's utility belt
MIT License
621 stars 118 forks source link

Library organization #1

Closed fogus closed 11 years ago

fogus commented 11 years ago

The underscore.contrib library should be organized along separations of functionality as _.mixins. Underscore is organized in the following ways:

We could certainly organize the same way, but maybe something less coarse is in order:

Or maybe something more technical:

This is an invitation for ideas. I'm not married to either of these schemes and would like feedback if you have some ideas.

knowtheory commented 11 years ago

Yeah, go with something that is as descriptive of its members' functionality as possible.

My temptation is to ask whether our immediate goals could be achieved simply by adding subheadings under Underscore's existing categories?

fogus commented 11 years ago

I think that it could. Would we then organize as fine-grained mixins as well as aggregate mixins? I think that would be kind of nice.

puffnfresh commented 11 years ago

Monads! Trampolines!

Exciting :smile:

fogus commented 11 years ago

Initial proposed layout:

An example file would be named underscore.object.builders.js and would be structured in effect as follows:

(function(root) {
  var _ = root._;

  // helpers
  // ...

  _.mixin({
    merge: function() { ... }
  });

})(this);

To use that library you could just add the following:

<script type="text/javascript" src="underscore.js"></script>
<script type="text/javascript" src="underscore.object.builders.js"></script>

There are a couple of open questions:

  1. How to enforce inter-contrib dependencies? Documentation?
  2. How to detect/handle is Underscore has been noConflict'd?
knowtheory commented 11 years ago

There's another question to add into the mix:

3) How will API version syncing/changes work?

Will underscore-contrib target the most recently cut version, or should we just ask users to track functional compatibility via a test suite + whatever version of underscore they wish to test against? We should see about testing against both a stable release and master perhaps in Travis.

bjmiller commented 11 years ago

My $0.02: Target the most recent stable release, run tests against the edge master. When Underscore releases a new version, go through all the failures, and try to clean them up then. I suspect that very few things will actually turn red from one release to the next, so it would (hopefully) be trivial to cut a new contrib version whenever a new Underscore version is cut. It's not exactly the most volatile code base.

fogus commented 11 years ago

I have the latest tagged version in the test suite, but it would be nice to build a test grid out of underscore.latest, underscore.last, underscore.master (at least). Does Travis helps us with this?

tgriesser commented 11 years ago

This is looking really great.

How to detect/handle is Underscore has been noConflict'd?

Wouldn't this be on the user to wait on calling noConflict until all appropriate _ libs have been loaded?

fogus commented 11 years ago

Wouldn't this be on the user

My question really came from a position of ignorance. I've not needed the use _.noConflict so I'm not aware of the potential complications (if any) that it might have on contrib libraries. Maybe the answer is: no complications - move on?

puffnfresh commented 11 years ago

What happens when a library wants to export _ but doesn't want to assign it to the global object?

// Include _.js here
var mylibrary = {
    _: _.noConflict(),
    method1: method1
};

So the contrib libraries need a way of extending _ without having to pollute the global _, right?

knowtheory commented 11 years ago

the contrib libs just need to grab a reference to so that they know where .mixin lives.

The standard way of doing this is, load up underscore, which will snag the global , load all of your other libraries which need a reference to underscore and can acquire them as , and then call .noConflict() which will restore back to its previous state.

puffnfresh commented 11 years ago

@knowtheory makes sense. Thanks.

fogus commented 11 years ago

I think I've settled on an organization/import scheme as shown in the existing code. I'm going to close this case and insist any changes and module names be addressed as new contrib libraries come in.