I think it's useful to clarify why this is the case. RequireJS has three goals (http://requirejs.org/docs/why.html#2):HTML Imports solves the first two easily. <link rel="import"> works within an imported HTML file just as well as it does from the main index.html (or whatever) file.
- Some sort of #include/import/require
- ability to load nested dependencies
- ease of use for developer but then backed by an optimization tool that helps deployment
The third point has been addressed here (http://lists.w3.org/Archives/Public/public-webapps/2012OctDec/0479.html) and here (https://groups.google.com/forum/#!searchin/polymer-dev/concatenate/polymer-dev/jXkjkwjbIG8/WJN90ck6v9wJ). Basically, HTML Imports places no restrictions on what's in the imported file. For example, Vulcanizer (https://github.com/Polymer/labs/tree/master/vulcanize) is a tool that concatenates all of your individual component HTML files into a single one. Then all you have to do is rewrite your main HTML file to pull in that one instead of the individual ones. See the second link (the Google Groups one) for Addy Osmani's progress on doing all of this with grunt.js.
<snip>
--To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/3f285843-6e60-4038-8645-5c72eabeef09%40googlegroups.com.
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
Visit this group at http://groups.google.com/group/polymer-dev.
I'm already wrapping, always, as a rule.The situation I describe is with respect to loading via script tag 3rd party libraries that aren't themselves implemented as custom elements.Suppose I have a project which imports CustomA, which loads by script tag PopularLibX version 1.3; and I also import 3rd party CustomB, which also loads by script tag PopularLibX, but incompatible version 2.1.If both PopularLibX versions are setting up `window.popLibX` and the PopularLibX author didn't implement something like a lodash `noConflict` method, then there's going to be a problem. The problem is exacerbated if my project imports lots of elements which may in turn load by script tag lots of libraries with conflicting versions or conflicting use of the global namespace.This is exactly the type of thing that AMD (e.g. RequireJS) can help with inasmuch as loading a module doesn't depend on hanging something on `window`, and thus it's possible to have two incompatible versions of a library loaded at the same time without causing any problems for the consuming modules.I'm not saying that I think integrating RequireJS into Polymer is necessarily the way to go. But I think that as Polymer grows up in the near term, and we look toward a future where custom elements, potentially quite a lot at a time, are specified as dependencies by way of something like bower (and they in turn have non-custom element dependencies like PopularLibX, which they load by script tag), then this will be more of an issue.It's possible I've overlooked something and am overblowing this concern, so I appreciate your feedback.Thanks.--Michael Bradley, Jr.@michaelsbradley
On Friday, July 26, 2013 8:04:48 PM UTC-5, Eric Bidelman wrote:
There was a good thread on the namespace question a few weeks back:Basically, HTMLImports has nothing to say about encapsulation or conflictavoidance. It's simply a convenient tool for including HTML in other HTML.To prevent global pollution for Custom Elements, one thing you could do is wrap the constructor returned by document.register() in a namespace:
<snip>
--
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
Visit this group at http://groups.google.com/group/polymer-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/94b747d1-9039-4efd-b2b6-e4607bb29bce%40googlegroups.com.
I think it's useful to clarify why this is the case. RequireJS has three goals (http://requirejs.org/docs/why.html#2):
- Some sort of #include/import/require
- ability to load nested dependencies
- ease of use for developer but then backed by an optimization tool that helps deployment
HTML Imports solves the first two easily. <link rel="import"> works within an imported HTML file just as well as it does from the main index.html (or whatever) file.The third point has been addressed here (http://lists.w3.org/Archives/Public/public-webapps/2012OctDec/0479.html) and here (https://groups.google.com/forum/#!searchin/polymer-dev/concatenate/polymer-dev/jXkjkwjbIG8/WJN90ck6v9wJ). Basically, HTML Imports places no restrictions on what's in the imported file. For example, Vulcanizer (https://github.com/Polymer/labs/tree/master/vulcanize) is a tool that concatenates all of your individual component HTML files into a single one. Then all you have to do is rewrite your main HTML file to pull in that one instead of the individual ones. See the second link (the Google Groups one) for Addy Osmani's progress on doing all of this with grunt.js.In short: There's really no reason to use RequireJS *and* HTML Imports unless you're jumping into an app that's already using RequireJS and can't easily be modified to change that.As to your second question, here are the changes I could find (this list is by no means comprehensive):
- Adds a "register" function to "document" (http://www.polymer-project.org/platform/custom-elements.html#documentregister)
- Overrides "document.createElement" to support creation of custom elements (http://www.polymer-project.org/platform/custom-elements.html#using-a-custom-element)
- Adds a "createShadowRoot" method and a "shadowRoot" property to the HTMLElement prototype (http://www.polymer-project.org/platform/shadow-dom.html#basic-usage)
- Modifies HTMLElement's prototype's "innerHTML" and "firstChild" properties, as well as basically anything that returns a Node (http://www.polymer-project.org/platform/shadow-dom.html#wrappers)
- Adds a "bind" method to all DOM Node objects (https://github.com/Polymer/mdv/blob/master/docs/node_bind.md#why-nodeprototypebind)
- Looks like there's a "createBinding" method on HTMLElement's prototype. Don't have any docs for this.
What about global scope issues?With AMD, you don't have to worry about using or implementing a `noConflict` method as found in popular libraries like lodash, as a module doesn't cause side-effects in the global scope (i.e. `window`) unless the script's author deliberately causes such a side-effect.But with HMTL Imports, it's not clear to me that you can achieve a similar level of encapsulation -- is it achievable?Now, if every library in use was implemented as a custom element that hung everything on its constructor and/or instances, then this would be a moot point. However, it seems unlikely that one would or would want to re-implement or somehow wrap a lib like lodash into a custom element -- or maybe I'm wrong on that point and that *is* the direction component-proponents would expect things to go. Thoughts?
I'm already wrapping, always, as a rule.The situation I describe is with respect to loading via script tag 3rd party libraries that aren't themselves implemented as custom elements.Suppose I have a project which imports CustomA, which loads by script tag PopularLibX version 1.3; and I also import 3rd party CustomB, which also loads by script tag PopularLibX, but incompatible version 2.1.If both PopularLibX versions are setting up `window.popLibX` and the PopularLibX author didn't implement something like a lodash `noConflict` method, then there's going to be a problem. The problem is exacerbated if my project imports lots of elements which may in turn load by script tag lots of libraries with conflicting versions or conflicting use of the global namespace.This is exactly the type of thing that AMD (e.g. RequireJS) can help with inasmuch as loading a module doesn't depend on hanging something on `window`, and thus it's possible to have two incompatible versions of a library loaded at the same time without causing any problems for the consuming modules.I'm not saying that I think integrating RequireJS into Polymer is necessarily the way to go. But I think that as Polymer grows up in the near term, and we look toward a future where custom elements, potentially quite a lot at a time, are specified as dependencies by way of something like bower (and they in turn have non-custom element dependencies like PopularLibX, which they load by script tag), then this will be more of an issue.It's possible I've overlooked something and am overblowing this concern, so I appreciate your feedback.
In short: There's really no reason to use RequireJS *and* HTML Imports unless you're jumping into an app that's already using RequireJS and can't easily be modified to change that.
var Q = require('Q');
var d3 = require('d3');
var storage = require('lls');
...Scott, don't you have a new HTML import + JS module loader POC or brain dump somewhere? Am I making that up?
Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/ca2cc747-8c1e-476e-8f9d-774f622a9ebb%40googlegroups.com.
Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/58da4fe4-caee-4119-b8d9-5e09651aebc9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.