Manual bootstrap in Polymer

大城市里の小女人 提交于 2019-12-08 09:43:53

问题


Is there an imperative way to bootstrap Polymer, in the style of Angular bootstrap?

The docs give details about individual elements lifecycle, but nothing about the framework itself.

I'm looking for a way to reconcile Polymer with requirejs and I need to force a single point of entry into my app. If I can bootstrap Polymer from within the requirejs data-main, I'm good.

related material:
- Working with Polymer and requirejs
- Require.js to load all resources for an app, including Polymer
- Polymer + requirejs: Attributes on were data bound prior to Polymer upgrading the element
- requirejs+polymer thread on google group
- polymer+requirejs gist


回答1:


I've figured out a simple way to manually trigger my app to bootstrap (at least it works for single page app), here's how you can do it too:

  • Don't import any of your custom-element.html from the index.html or any other page directly imported from the index. Your polymer-ready event should fire straight away but none of your custom elements will be loaded. This may require additional steps on your part to avoid FOUC and what not.
  • When you want to bootstrap your app, use the polymer.import helper function to kick things off. If you have a hierarchy of elements importing each other, you only need to manually import the top-level elements, the others will be imported through html imports. You can repeat this with different elements at different times if you want to import parts of your app dynamically.


来源:https://stackoverflow.com/questions/28673242/manual-bootstrap-in-polymer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!