Skip to content
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

Backbone no longer works w/ Ender (Backbone.$ not set when exports is defined) #3031

Closed
symmetriq opened this issue Feb 28, 2014 · 5 comments
Labels

Comments

@symmetriq
Copy link

I use Backbone as a module in some of my Ender-built libraries. As of Backbone 1.1.1, the Backbone.$ reference is now undefined instead of pointing at the global $. I assume there's a valid reason to omit $ in some situations, but in this case it prevents Backbone from working as an Ender module.

Because exports always exists when modules are part of an Ender library, $ doesn't get passed to factory:

// Next for Node.js or CommonJS. jQuery may not be needed as a module.
} else if (typeof exports !== 'undefined') {
  var _ = require('underscore');
  factory(root, exports, _);

This is where we really need to end up, but it's now unreachable in the context of an Ender library:

// Finally, as a browser global.
} else {
  root.Backbone = factory(root, {}, root._, (root.jQuery || root.Zepto || root.ender || root.$));
}
@tgriesser
Copy link
Collaborator

Yep, this was brought up in a few other tickets (see the end of #2997).

The solution is to do:

Backbone.$ = $;

wherever Backbone is first referenced.

@symmetriq
Copy link
Author

Yeah, I actually tried that. The trouble is, due to the way Ender modules are created, there's no way to add that reference without losing the ability to integrate Backbone into $. Ender integrates modules' methods into $ via $.ender(require('module_name')). If I attempt to add the $ reference first (e.g. like below), it results in an infinite loop (until the max stack size limit is reached), presumably due to a circular reference somewhere:

$.ender((function () {
  var b = require('backbone');
  b.$ = $;
  return b;
}()));

I've managed to work around this by just not integrating Backbone into $ (which means one more global variable) and updating all references to Backbone methods, but I'm wondering what was gained by breaking this usage pattern?

At the very least, the root.ender reference might as well be removed from the latter block in my first post, since that block is now unreachable when Backbone is part of an Ender library.

@jashkenas jashkenas reopened this Feb 28, 2014
@jashkenas jashkenas added bug and removed question labels Feb 28, 2014
@jashkenas
Copy link
Owner

@symmetriq Would you like to send in a patch that fixes the Ender loading problem? Is such a patch possible?

@symmetriq
Copy link
Author

@jashkenas Done: #3038

@akre54
Copy link
Collaborator

akre54 commented Nov 4, 2014

closing in favor of #3038.

@akre54 akre54 closed this as completed Nov 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants