-
Notifications
You must be signed in to change notification settings - Fork 59
Add support for lazy-imports of iron-lazy-pages #600
Conversation
@TimvdLippe I have to think about this one. Theoretically any element could be using imports as lazy, and we can't add support for all of them. My initial reaction is that I'd rather have one pattern of specifying lazy imports, and rework iron-lazy-pages to use lazy imports. I see this as similar to the ES6 import statement vs dynamic import(). Bundlers can treat dynamic import() as lazy edges, but really any function could ultimately pass an argument to a dynamic import(). It's unlikely that a bundler will add support for every library's import wrapper. It'd be good to get issues going for features like this so we can discuss before PR time, but thanks as always for the contributions! |
@TimvdLippe is there a way you could change |
@justinfagnani Ah yeah sorry, I extensively discussed this particular feature with @rictic on both Slack on GitHub. This morning I got very excited and actually built this PR, without realising that it needs a proper introduction too 😄 A previous discussion was in a shop PR: Polymer/shop#114 (comment) The essence comes down to the following: with the current solutions, users have to copy information a lot of the times. There are hidden dependencies between dynamic With a single (statically analyzable) source of truth, the user experience is a lot better. There is less room for error, the intent is a lot clearer and the tools can automatically use the source of truth. This particular pull request showcases what one of the possibilities is. I never had the intention to integrate Still, I am convinced that this PR serves a better experience for users using the various tools, although I would love to abstract away the hidden dependency on my |
Hey @TimvdLippe thanks for the explanation. I'm still convinced that we need to a basic set of primitives for describing the dependency graph, at least for the built-in functionality. Basically, I agree with the single-source-of-truth principle, and it should be lazy-imports. lazy-imports will be able to completely replace fragments when plumbed through the Bundler.
I'd much rather see <dom-module id="my-element">
<link rel="lazy-import" group="foo" href="foo.html">
<template>
<iron-lazy-pages attr-for-selected="data-route" selected="{{route}}">
<template is="iron-lazy-page" data-route="foo" group="foo">
Foo page
</template>
</iron-lazy-pages>
</template>
</dom-module> The problem with adding support for iron-lazy-pages directly to the Analyzer is that we would have to do the same for any other element that defined implicit lazy edges in the dependency graph, when I'd rather point out the correct pattern to follow to get analysis and bundling support automatically. |
@justinfagnani I definitely agree that the lazy import is better than the fragments in polymer.json. The concern I have is that it very much bloats the code. For example, if you have 25 routes in your application, you would need to duplicate this for every route, having at least 50 lines of code for essentially the same thing. In our experience, we hit the problem of forgetting routes, misspelling and not discovering the error at build time. Even if In essence, the pattern used in Shop and PSK is that the imports are based on the route name, and invoked via As I said, I would like to refrain from adding official support for |
@TimvdLippe thanks for the interesting PR. I'm cleaning up some things now, so I'm going to close this, but I'm sure we'll discuss this type of feature in issues soon. |
@rictic So I was really excited about this PR and did not want to wait till my weekend 😂
This pull request introduces lazy-import support for the analyzer. It takes the
iron-lazy-pages
definition and can determine what the lazy imports are (without extrarel="lazy-import"
tags).I have added 2 tests to verify the correct behavior. One is a unit test which just uses
DomModuleScanner
. The second one is an integration test, which I think works correct now. I have yet to try this out on a real application, but the edges/loading behavior of the analyzer is still vague for me.Please let me know what you think!