-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for CommonJS, AMD, and global namespace usage methods. #110
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e1ec181
Add support for CommonJS, AMD, and global namespace usage methods.
bartek 1fbebb2
Add jquery, underscore to package.json dependencies
bartek 73dd489
Resolve jshint warnings.
bartek f3dd12e
Add test to ensure NestedModel is attached to Backbone when using req…
bartek 27634ee
Use grunt-mocha-test instead of grunt-tape due to node 0.8 compatibil…
bartek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/*global describe, it*/ | ||
var assert = require('assert'); | ||
|
||
var Backbone = require('backbone'); | ||
require('../backbone-nested'); | ||
|
||
describe("CommonJS support", function() { | ||
it('should attach to Backbone when require backbone-nested', function() { | ||
assert.ok(Backbone.NestedModel); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking that it shouldn't modify the
Backbone
object if a module loader is detected (and maybe not at all, come to think of it) – not very Node-like, y'know? However, could be convinced that this is ok for consistency's sake, and also fine for initial Node support. Thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might be a good approach, I'm not a fan of the mysterious, in-place modification but that's how it was done with globals so I stuck to it.
Perhaps something like this?
If you're keen on not modifying it in the long term, that might be a better approach, but I feel to be consistent, and for this initial support, we can continue modifying it in-place, and open another PR for that issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's reasonable – @gkatsev?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option is to pass in a Backbone object into backbone-nested which would then modify it.
Anyway, it seems like most others of these types do modify backbone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something to consider in the future is having backbone-nested return a function that accepts a backbone object to modify.
so, you do:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modifying the
Backbone
object is probably a Bad Idea ™️ anyway – I've been thinking we should move to just having it create aNestedModel
object.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@afeld Love that approach. The in-place modification of Backbone looks like it might become inconsistent with how other modules are going.
For example, when using Backbone with browserify, the suggested approach to hooking up jQuery is now:
As the zen of Python states, "Explicit is better than implicit" :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My latest suggestion modifies backbone explicitly. It just does it for the user, explicitly, when the user wants it done, and on whatever specific object the user wants it done to.
Since we're just adding a new property to the backbone object, just returning
NestedModel
is more than reasonable.