-
Notifications
You must be signed in to change notification settings - Fork 659
Conversation
@@ -2387,4 +2405,8 @@ | |||
// @@include('../../tmp/js/hopscotch_templates.js') // | |||
}()); |
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 believe we could get around swapping out window.hopscotch with a couple of changes...
- Use
(function(){...}).call(winHopscotch);
- Update the namespace for the
jst
task inGruntfile.js
to usetemplates
instead ofhopscotch.templates
.
Hi @stebunovd, thanks for the pull request! Would love to see Hopscotch work well in whichever context its used within. A contemplation about how to best handle Hopscotch in multiple environments... Originally, I believe this was something we were planning to address as part of refactoring Hopscotch in 0.3.0. When originally thinking through the problem, the solution I was leaning towards was to use common environment-agnostic JS code that was then included (using the Do we believe this sort of build target separation be useful, or would this just convolute things? |
Hi @zimmi88, thank you for pointing out how to avoid that hack for templates. the pattern I used here for AMD/CommonJS support is called UMD, see https://github.com/umdjs/umd. This is a well-tested and widely used solution, which can be found in many JS libraries. Size overhead doesn't seem to be large, and having one universal file looks simpler and clearer from my perspective. In most cases users want all libraries in their environment to support the same format, either AMD, or CommonJS, or browser globals, so auto-detect works fine. Even if I want to do something different, say export library object from CommonJS environment to browser global scope, this is pretty easy to do either by single line of code |
} | ||
context[namespace] = factory(context.jQuery, context.YAHOO); | ||
} | ||
}(this, (function(jQuery, YAHOO) { |
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.
We should remove jQuery and YAHOO from factory params, since they are optional library dependencies. Somebody quickly looking at the source code might assume they are hard dependencies. You should still be able to do hasJquery = (typeof jQuery !== undefinedStr),
inside factory method, since it will assume window scope anyway.
Thank you for the pull request! Overall these changes look good to me. My only concern is |
A matter of habit. I write all my JS code with |
Looks good to me! I'll pull it in tomorrow if there are no other comments. |
Add support for AMD and CommonJS
no jQuery dependency for AMD or CommonJS, but jQuery will be used if available in global scope. All tests passing. Solves #150