developer guide

接下来看声明属性

声明属性

声明属性时,可设定的参数

type:属性反序列化
value:[function(){}],配置属性默认值
readonly
reflectToAttribute
默认为false,attribute转为property,firstName-->firstname, first-name-->firstName;
true时,相反,规则相同。
不明白property和attribute有什么区别?
在js中的叫property,在html中的叫attribute。property和attribute可以相互映射,也叫序列化与反序列化。
notify
computed
observer:function,property改变后,会调用此函数
observers:每个property需要设定默认值,函数会调用新值(函数内部用newValue表示新值);也可以观察子属性;
观察所有的子属性:user.manager.*,函数内部有三个属性path,value,base。
看到:http://docs.polymerchina.org/1.0/docs/devguide/properties.html#array-observation

数组监听

users: {
type: Array,
value: function() {
return [];
}
} observers: [
'usersChanged(users.*)'
], usersChanged: function(changeRecord) {
//会给监听函数传users.splices作为参数,记录了操作的细节。这些操作需要使用polymer提供的数组改变方法来执行
if (changeRecord.path == 'users.splices') {
// a user was added or removed
} else {
// an individual user or its sub-properties changed
// check "changeRecord.path" to determine what changed
}
}

  

notify:true

property value改变,则会调用property-changed的事件处理程序

readonly

//为什么要加这个函数?
responseHandler: function(response) {
this._setResponse(response);
}

  

computed properties

//依赖的属性以改变,则会重新计算
//所有依赖的属性都被定义(!==undefined)了,才会调用计算函数。所以被依赖的函数要有初始值。
fullName: {
type: String,
computed: 'computeFullName(first, last)'
}

把property映射为attribute:property和attribute的值同步

response: {
type: Object,
 //只需要设置这个属性
reflectToAttribute: true
}

属性序列化:

property--attribute:property value需要进行序列化,与property type有关;

局部DOM

local DOM; light DOM(children);browser通过shadow dom或者shady dom来创建local dom,默认是shady dom。

//id和is属性相同
//陈述部分
<dom-module id="x-foo">
<template>I am x-foo!</template>
</dom-module> <script>
//命令部分
Polymer({
is: 'x-foo'
});
</script>
//推荐把陈述和命令放在一个html中,和main file分开

节点的自动发现

<dom-module id="x-custom">
<template>
Hello World from <span id="name"></span>!
</template>
</dom-module> <script> Polymer({ is: 'x-custom', ready: function() {
    //通过this.$.{id}来找到静态节点
this.$.name.textContent = this.name;
} }); </script> //动态节点
this.$$(selector):只返回第一个

DOM分发

通过 <template>的<content>元素,把local dom和light dom结合起来,

DOM API

polymer提供自定义的API来操作local DOM和light DOM,这些API与原生的方法一样,只是会返回array,而不是nodelist。必须使用polymer提供的方法,而不能使用原生的方法

//使用append和insertBefore给polymer自定义的元素,增加子元素;自定义元素用this.root来表示
Polymer.dom(parent).appendChild(node)
Polymer.dom(parent).insertBefore(node, beforeNode)
Polymer.dom(parent).removeChild(node)
//使用dom.flush来执行以上操作
Polymer.dom.flush()
Parent and child APIs:
Polymer.dom(parent).childNodes
Polymer.dom(node).parentNode
Polymer.dom(node).firstChild
Polymer.dom(node).lastChild
Polymer.dom(node).firstElementChild
Polymer.dom(node).lastElementChild
Polymer.dom(node).previousSibling
Polymer.dom(node).nextSibling
Polymer.dom(node).textContent
Polymer.dom(node).innerHTML Query selector:
Polymer.dom(parent).querySelector(selector)
Polymer.dom(parent).querySelectorAll(selector) Content APIs:
Polymer.dom(contentElement).getDistributedNodes()
Polymer.dom(node).getDestinationInsertionPoints() Node mutation APIs:
Polymer.dom(node).setAttribute(attribute, value)
Polymer.dom(node).removeAttribute(attribute)
Polymer.dom(node).classList //使用以上API,可以保证shady dom能动态分发content元素;如果改变和类和属性,没有使用polymer API,则调用distributeContent强制更新分发。

这里提到的例子还没做

Events

事件监听器的设置

<dom-module id="x-custom">
<template>
<div>I will respond</div>
<div>to a tap on</div>
<div>any of my children!</div>
//打算给它加事件,所以设置一个id
<div id="special">I am special!</div>
   //与上一种方法相比,这种方式,不用给元素加id
   <div on-click='testClick'>on click</div>
</template>
</dom-module> <script> Polymer({ is: 'x-custom', listeners: {
    //给host element加tap事件
'tap': 'regularTap',
    //给id为special的元素加tap事件
'special.tap': 'specialTap'
}, regularTap: function(e) {
alert("Thank you for tapping");
}, specialTap: function(e) {
alert("It was special tapping");
},   testClick: function(e){
    alert('on click');
  } }); </script>

手势事件:先不看

事件重定向:有点麻烦,因为搞不懂哪几个dom

行为

看不懂

公共函数

所有的polymer元素继承自Polymer.Base,它实现了一些公共函数

$$(selector):返回 元素的local dom中第一个匹配的元素

toggleClass(name, boolean, [node]):boolean为true,给host元素加name的类;相反;如果node有值,则给node加,而不是给host元素加

toggleAttribute(name, boolean, [node]):

attributeFollows(name, newNode, oldNode):把一个boolean属性,从oldnode移到newnode,oldnode不设置,newnode设置

fire(type, [detail], [options]):触发一个自定义事件,options包括:node(默认为this),bubbles(true),cancelable(是否能被preventDefault取消,默认false)

全局设置

<html>
<head>
<meta charset="utf-8">
<script src="components/webcomponentsjs/webcomponents-lite.js"></script>
<script>
//在引入polymer库之前,进行设置
window.Polymer = window.Polymer || {};
window.Polymer.dom = 'shadow';
</script>
<!-- import a component that relies on Polymer -->
<link rel="import" href="elements/my-app.html">
</head>
<body>

也可以通过url进行设置:http://myserver.com/test-app/index.html?dom=shadow

dom
shadow:局部dom使用影子dom,将来默认使用影子dom
shady:局部dom使用shady dom,现在默认使用shady dom

shady dom

 

 

 

  

 

  

  

  

  

ploymer的更多相关文章

  1. Vue.js 2.0 和 React、Augular等其他框架的全方位对比

    引言 这个页面无疑是最难编写的,但也是非常重要的.或许你遇到了一些问题并且先前用其他的框架解决了.来这里的目的是看看Vue是否有更好的解决方案.那么你就来对了. 客观来说,作为核心团队成员,显然我们会 ...

  2. Riot - 比 Facebook React 更轻量的 UI 库

    Riot 是一个类似 Facebook React 的用户界面库,只有3.5KB,非常轻量.支持IE8+浏览器的自定义标签,虚拟 DOM,语法简洁.Riot 给前端开发人员提供了除 React 和 P ...

  3. 【转】谈谈Google Polymer以及Web UI框架的未来

    原文转自:http://www.csdn.net/article/2013-05-27/2815450-google-polymer 摘要:开发者Axel Rauschmayer在自己的博客上详解了G ...

  4. 实现checkbox组件化(Component)

    之前我写了一篇自定义checkbox的文章,通过css3实现自定义的checkbox,并没有使用当今流行的Reactjs, 或者Vuejs之类的进行组件化.但是很显然,这样封装的checkbox组件复 ...

  5. javascript组件化(转)

    javascript组件化(转) By purplebamboo 3月 16 2015 更新日期:3月 23 2015 文章目录 1. 最简陋的写法 2. 作用域隔离 3. 面向对象 4. 抽象出ba ...

  6. 【JavaScript】谈谈Google Polymer以及Web UI框架的未来

    摘要:开发者Axel Rauschmayer在自己的博客上详解了Google Polymer的设计理念与组成架构,深得Polymer开发者的认同.他认为Polymer这样高互操作性的设计才应该是Web ...

  7. Vue.js 2.0 和 React、Augular

    Vue.js 2.0 和 React.Augular 引言 这个页面无疑是最难编写的,但也是非常重要的.或许你遇到了一些问题并且先前用其他的框架解决了.来这里的目的是看看Vue是否有更好的解决方案.那 ...

  8. 基于LeanCloud云引擎的Web全栈方案

    LeanEngine-Full-Stack The FULL STACK DEVELOPER 复杂的项目, 协作分工, 自动化流程,代码组织结构,框架选择,国际化方案等 Generator 或者See ...

  9. (转)javascript组件开发方式

    作为一名前端工程师,写组件的能力至关重要.虽然javascript经常被人嘲笑是个小玩具,但是在一代代大牛的前仆后继的努力下,渐渐的也摸索了一套组件的编写方式. 下面我们来谈谈,在现有的知识体系下,如 ...

随机推荐

  1. python json5

    install pip install json5 test a.json: { 'a':'b', 'aa':['b1','b2']} =========================== impo ...

  2. Pie(浮点数二分)

    Pie http://poj.org/problem?id=3122 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2454 ...

  3. Connections in Galaxy War(逆向并查集)

    Connections in Galaxy War http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3563 Time Limit ...

  4. Poor Warehouse Keeper

    Poor Warehouse Keeper http://acm.hdu.edu.cn/showproblem.php?pid=4803 Jenny is a warehouse keeper. He ...

  5. java POI创建Excel示例(xslx和xsl区别 )

    Java用来处理office类库有很多,其中POI就是比较出名的一个,它是apache的类库,现在版本到了3.10,也就是2014年2月8号这个版本. 在处理PPT,Excel和Word前,需要导入以 ...

  6. 一定要 先删除 sc表 中的 某元组 行,,, 再删除 course表中的 元组行

    一定要  先删除 sc表 中的  某元组   行,,, 再删除  course表中的  元组行 course表 SC表 删除  course表中的  元组行,,出现错误 sc    ---->参 ...

  7. Laravel Eloquent Model->isDirty() Function

    1 引言 introduction 有时,我们需要在 Model 某些属性发生变化时,作出相应的处理. 这时,我们可以使用 Model->isDirty() 方法进行判断. 2 场景 比如,姓名 ...

  8. Java数据结构和算法(二)顺序存储的树结构

    Java数据结构和算法(二)顺序存储的树结构 数据结构与算法目录(https://www.cnblogs.com/binarylei/p/10115867.html) 二叉树也可以用数组存储,可以和完 ...

  9. com.opensymphony.xwork2.config.ConfigurationManager.addConfigurationProvider

    一月 31, 2016 5:06:31 下午 org.apache.catalina.core.StandardContext filterStart 严重: Exception starting f ...

  10. android textview settext卡顿深层次原因

    最近在公司项目里面发现listview里面的textview在调用settext函数的时候非常耗时,当时都有点不敢相信,这是因为如果你把textview设置成wrap_content,则每次调用set ...