我有一个 Polymer 0.5 元素,主要用作库,我使用 mixins 将其注入到其他元素中。我将其格式化如下,所有 JSDoc 符号都显示在index.html
:
<polymer-element name="easy-search-lib" attributes="">
<template>
<content></content>
</template>
<script>
var EasySearch = {
/**
* Returns whether the given domain matches search.
*
* @method matches
* @param {String} query String being searched for.
* @param {String} text Text being searched within.
* @return {Boolean} Returns if there is a match.
*/
matches: function(query, text){
query = this.getQuery(query);
return query.test(text);
}
//...
};
Polymer(Polymer.mixin({
/**
* Convenience function for testing, binds EasySearch to Polymer element.
*
* @attribute EasySearch
* @type object
*/
EasySearch: EasySearch
}, EasySearch));
</script>
</polymer-element>
Polymer 1.0 用行为替换了 mixins,并给出了以下示例:
<script>
HighlightBehavior = {
properties: {
isHighlighted: {
type: Boolean,
value: false,
notify: true,
observer: '_highlightChanged'
}
},
listeners: {
click: '_toggleHighlight'
},
created: function() {
console.log('Highlighting for ', this, + 'enabled!');
},
_toggleHighlight: function() {
this.isHighlighted = !this.isHighlighted;
},
_highlightChanged: function(value) {
this.toggleClass('highlighted', value);
}
};
</script>
请注意,没有<dom-module id="highlight-behavior">
norPolymer({...})
元素声明。
我完全按照这个例子,但是当我访问 index.html 时什么都没有出现。所以我试着模仿我为 0.5 所做的事情:
<script>
var EasySearchLib = {
EasySearch : {
/**
* Returns whether the given domain matches search.
*
* @method matches
* @param {String} query String being searched for.
* @param {String} text Text being searched within.
* @return {Boolean} Returns if there is a match.
*/
matches: function(query, text){
query = this.getQuery(query);
return query.test(text);
}
//...
}
};
Polymer({
is: 'easy-search-lib',
properties: {
/**
* `fancy` indicates that the element should don a monocle and tophat,
* while checking its pocket watch.
*/
EasySearchLib: EasySearchLib
}
});
</script>
我还尝试声明属性分配 ( EasySearch: EasySearchLib.EasySearch
) 的变体并输入 abehaviors: [EasySearchLib]
但文档中没有显示任何内容。
在访问 index.html 时,获取行为/库文档的最佳方式是什么?