博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Polymer初探
阅读量:6944 次
发布时间:2019-06-27

本文共 3589 字,大约阅读时间需要 11 分钟。

Polymer是什么?

Polymer英文为

  • n.聚合物;多聚体
  • 网络高分子;聚合体;高分子聚合物

Image result for polymer

 

应用在Web组件场景, 表达的是, 一个一个小的Web组件,可以通过此框架聚合为一个 整个页面。

 

https://github.com/Polymer/polymer

Polymer lets you build encapsulated, reusable elements that work just like standard HTML elements, to use in building web applications.

 

Polymer is a lightweight library built on top of the web standards-based API's, and makes it easier to build your very own custom HTML elements. Creating reusable custom elements - and using elements built by others - can make building complex web applications easier and more efficient. By being based on the Web Components API's built in the browser (or where needed), Polymer elements are interoperable at the browser level, and can be used with other frameworks or libraries that work with modern browsers.

 

Web Components标准

http://www.cnblogs.com/ywb15ba/p/polymer.html

polymer由谷歌的Palm webOS团队打造,并在2013 Google I/O大会上推出,旨在实现Web Components,用最少的代码,解除框架间的限制的UI 框架。

 

 

polymer分层结构:

 

    元素层(Elemets), 分为UI elements(如select、tab)、 non-UI elements(如ajax、animate)

 

    核心层:polymer.html+polymer.js,是创建polymer element的必要依赖。

    基础层:platform.js,是平台兼容,和响应式代码实现的必要依赖,创建应用必须首先引入它。其中大部分API最终将成为原生浏览器API。

 

通过<link rel="import" href="component-name.html">方式引入组件,即Web Components的Imports规范。

 

 

规范

https://www.w3.org/TR/2013/WD-components-intro-20130606/

The component model for the Web ("Web Components") consists of five pieces:

  1. , which define chunks of markup that are inert but can be activated for use later.
  2. , which apply templates based on CSS selectors to affect rich visual and behavioral changes to documents.
  3. , which let authors define their own elements, with new tag names and new script interfaces.
  4. , which encapsulates a DOM subtree for more reliable composition of user interface elements.
  5. , which defines how templates, decorators and custom elements are packaged and loaded as a resource.

 

https://developer.mozilla.org/en-US/docs/Web/Web_Components

Web Components consists of several separate technologies. You can think of Web Components as reusable user interface widgets that are created using open Web technology. They are part of the browser, and so they do not need external libraries like jQuery or Dojo. An existing Web Component can be used without writing code, simply by adding an import statement to an HTML page. Web Components use new or still-developing standard browser capabilities.

 

Sometimes there is some confusion regarding Web Components and . Polymer is a framework that is based on Web Components technologies. You can make and use Web Components without Polymer.

http://fex.baidu.com/blog/2014/05/web-components-future-oriented/

首先需要说明的是这不是一篇 Web Components 的科普文章,如果对此了解不多推荐先读。有句古话-“授人以鱼,不如授人以渔”,如果把组件比作“鱼”的话,对于前端开发者而言,W3C组织制定的HTML标准以及浏览器厂商的实现都是“鱼”而不是“渔”,开发者在需求无法满足的情况下通过现有技术创造了各种组件,虽然短期满足了需求但是由于严重缺乏标准,导致同一个组件有成千上万的相似实现但它们却无法相互重用,这很大程度上制约了组件化的最大价值-重用,Web Components则在组件标准化方面向前迈了一大步。

 

DEMO

https://github.com/fdandan/polymer

 

index.html

  
Polymer Demo

 

 组件demo1

 

组件DEMO2

 

运行效果:

 

你可能感兴趣的文章
Diomidis Spinellis:有效的调试
查看>>
Visual Studio最新特性分析
查看>>
JS/CSS体积减少了67%,我们是如何做到的?
查看>>
金山云最新财报:Q4营收7.27亿,同比增长81%
查看>>
携程Redis容器化实践\n
查看>>
Python数据可视化2018:数据可视化库为什么这么多?
查看>>
QCon上海2015精彩演讲前瞻:一线互联网公司架构实践
查看>>
红帽企业版Linux成为Linux下的.NET Core的参考平台
查看>>
蚂蚁金服如何把前端性能监控做到极致?
查看>>
2019 SRE 调查报告:事故处理是主要工作,SRE 压力山大
查看>>
深入浅出Tensorflow(五):循环神经网络简介
查看>>
xpath学习
查看>>
Java工程师的成长路线图是什么?
查看>>
JavaOne 2016——首日亮点
查看>>
LintCode Coins in a line III
查看>>
EDU_BOOK 开发总结
查看>>
简单的支持网页画框拖拽缩放功能的js插件
查看>>
探究underscore源码(一)
查看>>
Java IO详解
查看>>
javascript之创建对象
查看>>