简体   繁体   English

Polymer是一个框架而不是库。如何模块化地使用Web组件?

[英]Polymer is a framework instead of a library. How can I modularly use web components?

The idea of web components is to modularize the web regardless of what framework you use. 无论您使用什么框架,Web组件的概念都是模块化Web。

The Polymer project promise the possibility to create web components, not to be a framework, so it should be possible to use it with any framework. Polymer项目承诺创建Web组件的可能性,而不是框架,因此应该可以将它与任何框架一起使用。 More than that, I should be able to just download the elements from the element catalog and use it without the polymer library, just with the webcomponents.js. 更重要的是,我应该能够从元素目录中下载元素,并在没有聚合物库的情况下使用它,只需使用webcomponents.js。

I recognize that this is an ongoing project and most of browser's vendors are still developing the web components requirements, but what I'm concluding so far is that the Polymer is becoming a new framework as I cannot use their elements without the Polymer library and the use with framework as Angular 2 is not yet working well. 我认识到这是一个正在进行的项目,并且大多数浏览器的供应商仍在开发Web组件要求,但到目前为止我得出的结论是,Polymer正在成为一个新的框架,因为我不能使用他们的元素而没有Polymer库和与框架一起使用,因为Angular 2尚未运行良好。

Is that a way to use web components in a real modular way without all the boilerplate that the Polymer suggest? 这是一种以真正的模块化方式使用Web组件的方法,而没有Polymer建议的所有样板吗?

TL;DR; TL; DR;

Polymer does not break the modularity merely by the fact that it's required to use Web Components built with it. Polymer不会因为需要使用使用它构建的Web组件而破坏模块性。 It is just a library, albeit opinionated, used to implement custom elements. 它只是一个图书馆,尽管是自以为是,用于实现自定义元素。

These elements are however still independent modules. 然而,这些元素仍然是独立的模块。 All of Polymer stuff should be hidden inside a component and not interfere with the outside. 所有聚合物材料都应该隐藏在组件内部而不会干扰外部。

Long read 长读

The idea of web components is to modularize the web regardless of what framework you use 无论您使用什么框架,Web组件的概念都是模块化Web

In a sense, yes. 从某种意义上说,是的。 Though Web Components target to modularize the DOM really. 虽然Web Components的目标是真正模块化DOM。 For general modularization, there are ES6 modules IMO. 对于一般模块化,有ES6模块IMO。

The Polymer project promise the possibility to create web components, not to be a framework, so it should be possible to use it with any framework. Polymer项目承诺创建Web组件的可能性,而不是框架,因此应该可以将它与任何框架一起使用。

I'm not sure what you expect from Polymer and Web Components in general. 我不确定您对聚合物和Web组件的期望。 The modularity of Web Components come from the fact that when used, they are just an ordinary part of the DOM tree. Web组件的模块化来自这样一个事实,即在使用时,它们只是DOM树的普通部分。 Any existing library can work with that. 任何现有的库都可以使用它。 Any Web Component is just a HTML element and exposes a uniform interface: attributes and events . 任何Web组件都只是一个HTML元素,并公开一个统一的接口: 属性和事件 What Polymer does is add some niceties on top of that so that you can enjoy data-binding , simpler custom element declarations , simpler events API , styling polyfill , shady DOM and more. Polymer所做的是在其上添加一些细节,以便您可以享受数据绑定更简单的自定义元素声明更简单的事件API样式polyfillshady DOM等等。

It's a dependency like any other and should not stop you from using Polymer (or Bosonic , or x-tag , or basic-web-components ) with any other web framework. 这是一种依赖性,不应该阻止您将Polymer(或Bosonic ,或x-tag基本Web组件 )与任何其他Web框架一起使用。

More than that, I should be able to just download the elements from the element catalog and use it without the polymer library , just with the webcomponents.js. 更重要的是,我应该能够从元素目录中下载元素,并在没有聚合物库的情况下使用它,只需使用webcomponents.js。

Where did you read that? 你在哪里读到的? Also, is it a problem that polymer.html is required for the components to work? 此外,组件工作还需要polymer.html吗? You may get the same with other Web Components libraries. 您可以使用其他Web Components库。

I recognize that this is an ongoing project and most of browser's vendors are still developing the web components requirements. 我认识到这是一个正在进行的项目,大多数浏览器供应商仍在开发Web组件要求。

I believe there is a need of clarification. 我认为需要澄清。 The vendors implement the Web Components spec and where it isn't ready, webcomponents.js fill in the blanks. 供应商实现了Web组件规范,并且没有准备好,webcomponents.js填补了空白。 Just as I write above however, Polymer is a little bit more, because it gives you more than pure specs. 就像我上面写的那样,Polymer更多一点,因为它给你的不仅仅是纯粹的规格。

Is that a way to use web components in a real modular way without all the boilerplate that the Polymer suggest? 这是一种以真正的模块化方式使用Web组件的方法,而没有Polymer建议的所有样板吗?

Not sure what is the bolierplate that you refer to, but yes, you can write Web Components in plain javascript (or in a minimal dependencies fashion ) but you will lose some of the sugar that Web Components give you. 不确定你所引用的bolierplate是什么,但是,你可以用普通的javascript (或以最小的依赖方式 )编写Web组件,但是你会丢失一些Web组件给你的糖。 It is just like arguing that one shouldn't use jQuery, because all that it does can be done without it. 这就像争辩说不应该使用jQuery,因为它所做的一切都可以在没有它的情况下完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM