add store doc

This commit is contained in:
dntzhang 2017-03-20 16:46:21 +08:00
parent 7aaac080aa
commit f0db85929b
10 changed files with 3482 additions and 291 deletions

188
docs/src/docs/cn/store.md Normal file
View File

@ -0,0 +1,188 @@
## Store 体系
先说说Store系统是干什么的
当我们组件之间拥有共享的数据的时候经常需要进行组件通讯。在Omi框架里组件通讯非常方便
* 通过在组件上声明 data-* 传递给子节点
* 通过在组件上声明 data 传递给子节点 (支持复杂数据类型的映射)
* 声明 group-data 把数组里的data传给一堆组件传递支持复杂数据类型的映射
* 完全面向对象,可以非常容易地拿到对象的实例,之后可以设置实例属性和调用实例的方法。比如(标记name、标记omi-id)
当然你也可以使用event emitter / pubsub库在组件之间通讯比如这个只有 200b 的超小库[mitt](https://github.com/developit/mitt) 。但是需要注意mitt兼容到IE9+Omi兼容IE8。
虽然组件通讯非常方便,但是各种数据传递、组件实例互操作或者循环依赖,让代码非常难看且难以维护。所以:
Omi.Store是为了让 组件通讯几乎绝迹 。虽然:
Redux 的作者 Dan Abramov 说过Flux 架构就像眼镜:您自会知道什么时候需要它。
但是,我不会告诉你
Omi Store 系统就像眼镜:您自会知道什么时候需要它。
因为Omi Store使用足够简便对架构入侵性极极极小(3个极代表比极小还要小)让数据、数据逻辑和UI展现彻底分离所以我的观点是
如果使用Omi请使用Omi.Store架构。
比如连这个[Todo例子](https://github.com/AlloyTeam/omi/tree/master/example/todo-store)都能使用Omi.Store架构。如果连复杂度都达不到Todo那么Omi其实都没有必要使用你可能只需要一个模板引擎便可。
### 定义 Omi.Store
Omi.Store是基类我们可以继承Omi.Store来定义自己的Store比如下面的TodoStore。
```js
import Omi from 'omi'
class TodoStore extends Omi.Store {
constructor(data , isReady) {
super(isReady)
this.data = Object.assign({
items:[],
text:'',
length:0
},data)
this.data.length = this.data.items.length
}
add(){
this.data.items.push(this.data.text)
this.data.text = ""
this.data.length = this.data.items.length
this.update()
}
updateText(text){
this.data.text = text
}
clear(){
this.data.items.length = 0
this.data.length = 0
this.data.text = ""
this.update()
}
}
export default TodoStore
```
TodoStore定义类数据的基本格式和数据模型的逻辑。
比如 this.data 就是数据的基本格式,
```js
{
items:[],
text:'',
length:0
}
```
add,updateText和clear就是数据模型的逻辑。
### 使用 Omi.Store
通过 new 关键字来使用TodoStore对象的实例。
```js
let store = new TodoStore({ /* 初始化配置 */ })
```
上面可以传入一些初始化配置信息store里面便包含了整个应用程序共享的状态数据以及相关数据逻辑方法(add,updateText,clear)。
当然这些初始化配置信息可能是异步拉取的。所以有两种方法解决异步拉取store配置的问题
* 先let store = new TodoStore(),再Omi.render,组件内部监听store.ready拉取数据更改store的data信息然后执行store.beReady()
* 拉取数据然后new TodoStore()再Omi.render
### 根组件注入 store
为了让组件树能够使用到 store可以通过Omi.render的第三个参数给根组件注入 store:
```js
Omi.render(new Todo(),'body',{
store: store
});
```
当然ES2015已经允许你这样写了:
```js
Omi.render(new Todo(),'body',{
store
});
```
两份代码同样的效果。
通过Omi.render注入之后在组件树的所有组件都可以通过 this.$store 访问到 store。
### 简便的 storeToData
storeToData这个函数是生命周期的一部分。且看下面这张图:
![storeToData](http://images2015.cnblogs.com/blog/105416/201703/105416-20170320163400955-825119056.png)
在render之前会去执行storeToData方法。所以该方法里面可以书写store的data到组件data的转换逻辑。比如
```js
class List extends Omi.Component {
storeToData(){
this.data.items = this.$store.data.items
}
render () {
return ` <ul> {{#items}} <li>{{.}}</li> {{/items}}</ul>`
}
}
```
再比如todo使用length和text:
```js
import Omi from '../../src/index.js';
import List from './list.js';
Omi.makeHTML('List', List);
class Todo extends Omi.Component {
install(){
this.$store.ready(()=>this.update())
}
storeToData(){
this.data.length = this.$store.data.items.length
this.data.text = this.$store.text
}
add (evt) {
evt.preventDefault();
this.$store.add();
}
handleChange(target){
this.$store.updateText(target.value);
}
render () {
return `<div>
<h3>TODO</h3>
<List name="list" />
<form onsubmit="add(event)" >
<input type="text" onchange="handleChange(this)" value="{{text}}" />
<button>Add #{{length}}</button>
</form>
</div>`;
}
}
export default Todo;
```
为什么要去写storeToData方法因为render只会使用this.data去渲染页面而不会去使用this.$store.data所以需要把数据转移到组件的this.data下。这样组件既能使用自身的data也能使用全局放this.$store.data了。
更为详细的代码可以[点击这里](https://github.com/AlloyTeam/omi/tree/master/example/todo-store)。

View File

@ -1,52 +1,53 @@
let config = {
menus: {
cn: [
{
active: true,
title: '快速开始',
currentIndex: 0,
list: [
{'name': '安装', md: 'installation'},
{'name': 'Hello World', md: 'hello_world'},
{'name': '组件', md: 'components'},
{'name': '组件通讯', md: 'communication'},
{'name': '生命周期', md: 'lifecycle'},
{'name': '事件处理', md: 'events'},
{'name': '条件判断', md: 'condition'},
{'name': '循环遍历', md: 'loop'},
{'name': '表单', md: 'form'},
{'name': '继承', md: 'inherit'},
{'name': '模板切换', md: 'template'},
{'name': '获取DOM节点', md: 'get_dom'},
{'name': '插件体系', md: 'plugin'},
{'name': 'Omi的理念', md: 'thinking_in_omi'}
]
}
],
en: [
{
title: 'QUICK START',
active: true,
currentIndex: 0,
list: [
{'name': 'Installation', md: 'installation'},
{'name': 'Hello World', md: 'hello_world'},
{'name': 'Components', md: 'components'},
{'name': 'Communication', md: 'communication'},
{'name': 'Lifecycle', md: 'lifecycle'},
{'name': 'Handling Events', md: 'events'},
{'name': 'Conditional Rendering', md: 'condition'},
{'name': 'Loop', md: 'loop'},
{'name': 'Forms', md: 'form'},
{'name': 'Inheritance', md: 'inherit'},
{'name': 'Templates', md: 'template'},
{'name': 'Get DOM', md: 'get_dom'},
{'name': 'Plugin', md: 'plugin'},
{'name': 'Thinking in Omi', md: 'thinking_in_omi'}
]
}
]
}
}
let config = {
menus: {
cn: [
{
active: true,
title: '快速开始',
currentIndex: 0,
list: [
{'name': '安装', md: 'installation'},
{'name': 'Hello World', md: 'hello_world'},
{'name': '组件', md: 'components'},
{'name': '组件通讯', md: 'communication'},
{'name': '生命周期', md: 'lifecycle'},
{'name': '事件处理', md: 'events'},
{'name': '条件判断', md: 'condition'},
{'name': '循环遍历', md: 'loop'},
{'name': 'Store体系', md: 'store'},
{'name': '表单', md: 'form'},
{'name': '继承', md: 'inherit'},
{'name': '模板切换', md: 'template'},
{'name': '获取DOM节点', md: 'get_dom'},
{'name': '插件体系', md: 'plugin'},
{'name': 'Omi的理念', md: 'thinking_in_omi'}
]
}
],
en: [
{
title: 'QUICK START',
active: true,
currentIndex: 0,
list: [
{'name': 'Installation', md: 'installation'},
{'name': 'Hello World', md: 'hello_world'},
{'name': 'Components', md: 'components'},
{'name': 'Communication', md: 'communication'},
{'name': 'Lifecycle', md: 'lifecycle'},
{'name': 'Handling Events', md: 'events'},
{'name': 'Conditional Rendering', md: 'condition'},
{'name': 'Loop', md: 'loop'},
{'name': 'Forms', md: 'form'},
{'name': 'Inheritance', md: 'inherit'},
{'name': 'Templates', md: 'template'},
{'name': 'Get DOM', md: 'get_dom'},
{'name': 'Plugin', md: 'plugin'},
{'name': 'Thinking in Omi', md: 'thinking_in_omi'}
]
}
]
}
}
export default config;

View File

@ -1,2 +1,2 @@
/*! @source http://purl.eligrey.com/github/classList.js/blob/master/classList.js */
/*! @source http://purl.eligrey.com/github/classList.js/blob/master/classList.js */
"document"in self&&("classList"in document.createElement("_")&&(!document.createElementNS||"classList"in document.createElementNS("http://www.w3.org/2000/svg","g"))?!function(){"use strict";var t=document.createElement("_");if(t.classList.add("c1","c2"),!t.classList.contains("c2")){var e=function(t){var e=DOMTokenList.prototype[t];DOMTokenList.prototype[t]=function(t){var n,i=arguments.length;for(n=0;i>n;n++)t=arguments[n],e.call(this,t)}};e("add"),e("remove")}if(t.classList.toggle("c3",!1),t.classList.contains("c3")){var n=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(t,e){return 1 in arguments&&!this.contains(t)==!e?e:n.call(this,t)}}t=null}():!function(t){"use strict";if("Element"in t){var e="classList",n="prototype",i=t.Element[n],s=Object,r=String[n].trim||function(){return this.replace(/^\s+|\s+$/g,"")},o=Array[n].indexOf||function(t){for(var e=0,n=this.length;n>e;e++)if(e in this&&this[e]===t)return e;return-1},c=function(t,e){this.name=t,this.code=DOMException[t],this.message=e},a=function(t,e){if(""===e)throw new c("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(e))throw new c("INVALID_CHARACTER_ERR","String contains an invalid character");return o.call(t,e)},l=function(t){for(var e=r.call(t.getAttribute("class")||""),n=e?e.split(/\s+/):[],i=0,s=n.length;s>i;i++)this.push(n[i]);this._updateClassName=function(){t.setAttribute("class",this.toString())}},u=l[n]=[],h=function(){return new l(this)};if(c[n]=Error[n],u.item=function(t){return this[t]||null},u.contains=function(t){return t+="",-1!==a(this,t)},u.add=function(){var t,e=arguments,n=0,i=e.length,s=!1;do t=e[n]+"",-1===a(this,t)&&(this.push(t),s=!0);while(++n<i);s&&this._updateClassName()},u.remove=function(){var t,e,n=arguments,i=0,s=n.length,r=!1;do for(t=n[i]+"",e=a(this,t);-1!==e;)this.splice(e,1),r=!0,e=a(this,t);while(++i<s);r&&this._updateClassName()},u.toggle=function(t,e){t+="";var n=this.contains(t),i=n?e!==!0&&"remove":e!==!1&&"add";return i&&this[i](t),e===!0||e===!1?e:!n},u.toString=function(){return this.join(" ")},s.defineProperty){var f={get:h,enumerable:!0,configurable:!0};try{s.defineProperty(i,e,f)}catch(d){void 0!==d.number&&-2146823252!==d.number||(f.enumerable=!1,s.defineProperty(i,e,f))}}else s[n].__defineGetter__&&i.__defineGetter__(e,h)}}(self));

View File

@ -1,37 +1,37 @@
<!DOCTYPE html>
<html>
<head lang="zh">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<title>Omi</title>
<link rel="shortcut icon" href="../asset/omi.ico">
<link rel="stylesheet" href="css/docs-d7bcd3f561.css">
<link rel="stylesheet" href="common/highlight/tomorrow-a2eb49c74d.css">
</head>
<body>
<!--[if lt IE 9]>
<script>
(function(){
document.body.innerHTML = "The docs website does not support IE8, IE7 and IE6...<br/>Please use modern browser!<br/>" +
"The website will redirect to GitHub after 3s."
setTimeout(function(){
window.location.href = 'https://github.com/AlloyTeam/omi';
},3000);
return;
})()
</script>
<![endif]-->
<!--[if IE 9]>
<script src="common/common/class_list.js"></script>
<![endif]-->
<script src="common/highlight/highlight.pack.js"></script>
<script src="common/remarkable.min.js"></script>
<script src="js/vendor.ef9e9af7.js"></script>
<!DOCTYPE html>
<html>
<head lang="zh">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<title>Omi</title>
<link rel="shortcut icon" href="../asset/omi.ico">
<link rel="stylesheet" href="css/docs-d7bcd3f561.css">
<link rel="stylesheet" href="common/highlight/tomorrow-a2eb49c74d.css">
</head>
<body>
<!--[if lt IE 9]>
<script>
(function(){
document.body.innerHTML = "The docs website does not support IE8, IE7 and IE6...<br/>Please use modern browser!<br/>" +
"The website will redirect to GitHub after 3s."
setTimeout(function(){
window.location.href = 'https://github.com/AlloyTeam/omi';
},3000);
return;
})()
</script>
<![endif]-->
<!--[if IE 9]>
<script src="common/common/class_list.js"></script>
<![endif]-->
<script src="common/highlight/highlight.pack.js"></script>
<script src="common/remarkable.min.js"></script>
<script src="js/vendor.fee7e33e.js"></script>
<script src="js/omi.b9df77fe.js"></script>
<script src="js/docs-cn.fc16bb62.js"></script>
</body>
<script src="js/docs-cn.7d2017f1.js"></script>
</body>
</html>

View File

@ -1,38 +1,38 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<title>Omi</title>
<link rel="shortcut icon" href="../asset/omi.ico">
<link rel="stylesheet" href="css/docs-d7bcd3f561.css">
<link rel="stylesheet" href="common/highlight/tomorrow-a2eb49c74d.css">
</head>
<body>
<!--[if lt IE 9]>
<script>
(function(){
document.body.innerHTML = "The docs website does not support IE8, IE7 and IE6...<br/>Please use modern browser!<br/>" +
"The website will redirect to GitHub after 3s."
setTimeout(function(){
window.location.href = 'https://github.com/AlloyTeam/omi';
},3000);
return;
})()
</script>
<![endif]-->
<!--[if IE 9]>
<script src="common/common/class_list.js"></script>
<![endif]-->
<script src="common/highlight/highlight.pack.js"></script>
<script src="common/remarkable.min.js"></script>
<script src="js/vendor.ef9e9af7.js"></script>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<title>Omi</title>
<link rel="shortcut icon" href="../asset/omi.ico">
<link rel="stylesheet" href="css/docs-d7bcd3f561.css">
<link rel="stylesheet" href="common/highlight/tomorrow-a2eb49c74d.css">
</head>
<body>
<!--[if lt IE 9]>
<script>
(function(){
document.body.innerHTML = "The docs website does not support IE8, IE7 and IE6...<br/>Please use modern browser!<br/>" +
"The website will redirect to GitHub after 3s."
setTimeout(function(){
window.location.href = 'https://github.com/AlloyTeam/omi';
},3000);
return;
})()
</script>
<![endif]-->
<!--[if IE 9]>
<script src="common/common/class_list.js"></script>
<![endif]-->
<script src="common/highlight/highlight.pack.js"></script>
<script src="common/remarkable.min.js"></script>
<script src="js/vendor.fee7e33e.js"></script>
<script src="js/omi.b9df77fe.js"></script>
<script src="js/docs-en.c32b6981.js"></script>
</body>
<script src="js/docs-en.af7f09ce.js"></script>
</body>
</html>

View File

@ -1,13 +1,13 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script>
window.location.href='./docs-cn.html'
</script>
</head>
<body>
</body>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script>
window.location.href='./docs-cn.html'
</script>
</head>
<body>
</body>
</html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -11,8 +11,8 @@ webpackJsonp([2],[
/***/ function(module, exports, __webpack_require__) {
/*!
* Omi v0.4.3 By dntzhang
* Github: https://github.com/AlloyTeam/omi
* Omi v0.4.3 By dntzhang
* Github: https://github.com/AlloyTeam/omi
* MIT Licensed.
*/
(function webpackUniversalModuleDefinition(root, factory) {
@ -141,14 +141,14 @@ webpackJsonp([2],[
};
}
/**
* Shim for "fixing" IE's lack of support (IE < 9) for applying slice
* on host objects like NamedNodeMap, NodeList, and HTMLCollection
* (technically, since host objects have been implementation-dependent,
* at least before ES6, IE hasn't needed to work this way).
* Also works on strings, fixes IE < 9 to allow an explicit undefined
* for the 2nd argument (as in Firefox), and prevents errors when
* called on other DOM objects.
/**
* Shim for "fixing" IE's lack of support (IE < 9) for applying slice
* on host objects like NamedNodeMap, NodeList, and HTMLCollection
* (technically, since host objects have been implementation-dependent,
* at least before ES6, IE hasn't needed to work this way).
* Also works on strings, fixes IE < 9 to allow an explicit undefined
* for the 2nd argument (as in Firefox), and prevents errors when
* called on other DOM objects.
*/
(function () {
'use strict';
@ -406,9 +406,9 @@ webpackJsonp([2],[
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
/*!
* mustache.js - Logic-less {{mustache}} templates with JavaScript
* http://github.com/janl/mustache.js
/*!
* mustache.js - Logic-less {{mustache}} templates with JavaScript
* http://github.com/janl/mustache.js
*/
/*global define: false Mustache: true*/
@ -433,9 +433,9 @@ webpackJsonp([2],[
return typeof object === 'function';
}
/**
* More correct typeof string handling array
* which normally returns typeof 'object'
/**
* More correct typeof string handling array
* which normally returns typeof 'object'
*/
function typeStr(obj) {
return isArray(obj) ? 'array' : typeof obj === 'undefined' ? 'undefined' : _typeof(obj);
@ -445,9 +445,9 @@ webpackJsonp([2],[
return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
}
/**
* Null safe way of checking whether or not an object,
* including its prototype, has a given property
/**
* Null safe way of checking whether or not an object,
* including its prototype, has a given property
*/
function hasProperty(obj, propName) {
return obj != null && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && propName in obj;
@ -488,27 +488,27 @@ webpackJsonp([2],[
var curlyRe = /\s*\}/;
var tagRe = /#|\^|\/|>|\{|&|=|!/;
/**
* Breaks up the given `template` string into a tree of tokens. If the `tags`
* argument is given here it must be an array with two string values: the
* opening and closing tags used in the template (e.g. [ "<%", "%>" ]). Of
* course, the default is to use mustaches (i.e. mustache.tags).
*
* A token is an array with at least 4 elements. The first element is the
* mustache symbol that was used inside the tag, e.g. "#" or "&". If the tag
* did not contain a symbol (i.e. {{myValue}}) this element is "name". For
* all text that appears outside a symbol this element is "text".
*
* The second element of a token is its "value". For mustache tags this is
* whatever else was inside the tag besides the opening symbol. For text tokens
* this is the text itself.
*
* The third and fourth elements of the token are the start and end indices,
* respectively, of the token in the original template.
*
* Tokens that are the root node of a subtree contain two more elements: 1) an
* array of tokens in the subtree and 2) the index in the original template at
* which the closing tag for that section begins.
/**
* Breaks up the given `template` string into a tree of tokens. If the `tags`
* argument is given here it must be an array with two string values: the
* opening and closing tags used in the template (e.g. [ "<%", "%>" ]). Of
* course, the default is to use mustaches (i.e. mustache.tags).
*
* A token is an array with at least 4 elements. The first element is the
* mustache symbol that was used inside the tag, e.g. "#" or "&". If the tag
* did not contain a symbol (i.e. {{myValue}}) this element is "name". For
* all text that appears outside a symbol this element is "text".
*
* The second element of a token is its "value". For mustache tags this is
* whatever else was inside the tag besides the opening symbol. For text tokens
* this is the text itself.
*
* The third and fourth elements of the token are the start and end indices,
* respectively, of the token in the original template.
*
* Tokens that are the root node of a subtree contain two more elements: 1) an
* array of tokens in the subtree and 2) the index in the original template at
* which the closing tag for that section begins.
*/
function parseTemplate(template, tags) {
if (!template) return [];
@ -628,9 +628,9 @@ webpackJsonp([2],[
return nestTokens(squashTokens(tokens));
}
/**
* Combines the values of consecutive text tokens in the given `tokens` array
* to a single token.
/**
* Combines the values of consecutive text tokens in the given `tokens` array
* to a single token.
*/
function squashTokens(tokens) {
var squashedTokens = [];
@ -653,11 +653,11 @@ webpackJsonp([2],[
return squashedTokens;
}
/**
* Forms the given array of `tokens` into a nested tree structure where
* tokens that represent a section have two additional items: 1) an array of
* all tokens that appear in that section and 2) the index in the original
* template that represents the end of that section.
/**
* Forms the given array of `tokens` into a nested tree structure where
* tokens that represent a section have two additional items: 1) an array of
* all tokens that appear in that section and 2) the index in the original
* template that represents the end of that section.
*/
function nestTokens(tokens) {
var nestedTokens = [];
@ -688,9 +688,9 @@ webpackJsonp([2],[
return nestedTokens;
}
/**
* A simple string scanner that is used by the template parser to find
* tokens in template strings.
/**
* A simple string scanner that is used by the template parser to find
* tokens in template strings.
*/
function Scanner(string) {
this.string = string;
@ -698,16 +698,16 @@ webpackJsonp([2],[
this.pos = 0;
}
/**
* Returns `true` if the tail is empty (end of string).
/**
* Returns `true` if the tail is empty (end of string).
*/
Scanner.prototype.eos = function eos() {
return this.tail === '';
};
/**
* Tries to match the given regular expression at the current position.
* Returns the matched text if it can match, the empty string otherwise.
/**
* Tries to match the given regular expression at the current position.
* Returns the matched text if it can match, the empty string otherwise.
*/
Scanner.prototype.scan = function scan(re) {
var match = this.tail.match(re);
@ -722,9 +722,9 @@ webpackJsonp([2],[
return string;
};
/**
* Skips all text until the given regular expression can be matched. Returns
* the skipped string, which is the entire tail if no match can be made.
/**
* Skips all text until the given regular expression can be matched. Returns
* the skipped string, which is the entire tail if no match can be made.
*/
Scanner.prototype.scanUntil = function scanUntil(re) {
var index = this.tail.search(re),
@ -748,9 +748,9 @@ webpackJsonp([2],[
return match;
};
/**
* Represents a rendering context by wrapping a view object and
* maintaining a reference to the parent context.
/**
* Represents a rendering context by wrapping a view object and
* maintaining a reference to the parent context.
*/
function Context(view, parentContext) {
this.view = view;
@ -758,17 +758,17 @@ webpackJsonp([2],[
this.parent = parentContext;
}
/**
* Creates a new context using the given view with this context
* as the parent.
/**
* Creates a new context using the given view with this context
* as the parent.
*/
Context.prototype.push = function push(view) {
return new Context(view, this);
};
/**
* Returns the value of the given name in this context, traversing
* up the context hierarchy if the value is absent in this context's view.
/**
* Returns the value of the given name in this context, traversing
* up the context hierarchy if the value is absent in this context's view.
*/
Context.prototype.lookup = function lookup(name) {
var cache = this.cache;
@ -788,16 +788,16 @@ webpackJsonp([2],[
names = name.split('.');
index = 0;
/**
* Using the dot notion path in `name`, we descend through the
* nested objects.
*
* To be certain that the lookup has been successful, we have to
* check if the last object in the path actually has the property
* we are looking for. We store the result in `lookupHit`.
*
* This is specially necessary for when the value has been set to
* `undefined` and we want to avoid looking up parent contexts.
/**
* Using the dot notion path in `name`, we descend through the
* nested objects.
*
* To be certain that the lookup has been successful, we have to
* check if the last object in the path actually has the property
* we are looking for. We store the result in `lookupHit`.
*
* This is specially necessary for when the value has been set to
* `undefined` and we want to avoid looking up parent contexts.
**/
while (value != null && index < names.length) {
if (index === names.length - 1) lookupHit = hasProperty(value, names[index]);
@ -822,25 +822,25 @@ webpackJsonp([2],[
return value;
};
/**
* A Writer knows how to take a stream of tokens and render them to a
* string, given a context. It also maintains a cache of templates to
* avoid the need to parse the same template twice.
/**
* A Writer knows how to take a stream of tokens and render them to a
* string, given a context. It also maintains a cache of templates to
* avoid the need to parse the same template twice.
*/
function Writer() {
this.cache = {};
}
/**
* Clears all cached templates in this writer.
/**
* Clears all cached templates in this writer.
*/
Writer.prototype.clearCache = function clearCache() {
this.cache = {};
};
/**
* Parses and caches the given `template` and returns the array of tokens
* that is generated from the parse.
/**
* Parses and caches the given `template` and returns the array of tokens
* that is generated from the parse.
*/
Writer.prototype.parse = function parse(template, tags) {
var cache = this.cache;
@ -851,14 +851,14 @@ webpackJsonp([2],[
return tokens;
};
/**
* High-level method that is used to render the given `template` with
* the given `view`.
*
* The optional `partials` argument may be an object that contains the
* names and templates of partials that are used in the template. It may
* also be a function that is used to load partial templates on the fly
* that takes a single argument: the name of the partial.
/**
* High-level method that is used to render the given `template` with
* the given `view`.
*
* The optional `partials` argument may be an object that contains the
* names and templates of partials that are used in the template. It may
* also be a function that is used to load partial templates on the fly
* that takes a single argument: the name of the partial.
*/
Writer.prototype.render = function render(template, view, partials) {
var tokens = this.parse(template);
@ -866,14 +866,14 @@ webpackJsonp([2],[
return this.renderTokens(tokens, context, partials, template);
};
/**
* Low-level method that renders the given array of `tokens` using
* the given `context` and `partials`.
*
* Note: The `originalTemplate` is only ever used to extract the portion
* of the original template that was contained in a higher-order section.
* If the template doesn't use higher-order sections, this argument may
* be omitted.
/**
* Low-level method that renders the given array of `tokens` using
* the given `context` and `partials`.
*
* Note: The `originalTemplate` is only ever used to extract the portion
* of the original template that was contained in a higher-order section.
* If the template doesn't use higher-order sections, this argument may
* be omitted.
*/
Writer.prototype.renderTokens = function renderTokens(tokens, context, partials, originalTemplate) {
var buffer = '';
@ -960,25 +960,25 @@ webpackJsonp([2],[
// All high-level mustache.* functions use this writer.
var defaultWriter = new Writer();
/**
* Clears all cached templates in the default writer.
/**
* Clears all cached templates in the default writer.
*/
mustache.clearCache = function clearCache() {
return defaultWriter.clearCache();
};
/**
* Parses and caches the given template in the default writer and returns the
* array of tokens it contains. Doing this ahead of time avoids the need to
* parse templates on the fly as they are rendered.
/**
* Parses and caches the given template in the default writer and returns the
* array of tokens it contains. Doing this ahead of time avoids the need to
* parse templates on the fly as they are rendered.
*/
mustache.parse = function parse(template, tags) {
return defaultWriter.parse(template, tags);
};
/**
* Renders the `template` with the given `view` and `partials` using the
* default writer.
/**
* Renders the `template` with the given `view` and `partials` using the
* default writer.
*/
mustache.render = function render(template, view, partials) {
if (typeof template !== 'string') {
@ -1762,15 +1762,15 @@ webpackJsonp([2],[
return fragment.childNodes[0];
}
/**
* Returns true if two node's names are the same.
*
* NOTE: We don't bother checking `namespaceURI` because you will never find two HTML elements with the same
* nodeName and different namespace URIs.
*
* @param {Element} a
* @param {Element} b The target element
* @return {boolean}
/**
* Returns true if two node's names are the same.
*
* NOTE: We don't bother checking `namespaceURI` because you will never find two HTML elements with the same
* nodeName and different namespace URIs.
*
* @param {Element} a
* @param {Element} b The target element
* @return {boolean}
*/
function compareNodeNames(fromEl, toEl) {
var fromNodeName = fromEl.nodeName;
@ -1791,21 +1791,21 @@ webpackJsonp([2],[
}
}
/**
* Create an element, optionally with a known namespace URI.
*
* @param {string} name the element name, e.g. 'div' or 'svg'
* @param {string} [namespaceURI] the element's namespace URI, i.e. the value of
* its `xmlns` attribute or its inferred namespace.
*
* @return {Element}
/**
* Create an element, optionally with a known namespace URI.
*
* @param {string} name the element name, e.g. 'div' or 'svg'
* @param {string} [namespaceURI] the element's namespace URI, i.e. the value of
* its `xmlns` attribute or its inferred namespace.
*
* @return {Element}
*/
function createElementNS(name, namespaceURI) {
return !namespaceURI || namespaceURI === NS_XHTML ? doc.createElement(name) : doc.createElementNS(namespaceURI, name);
}
/**
* Copies the children of one DOM element to another DOM element
/**
* Copies the children of one DOM element to another DOM element
*/
function moveChildren(fromEl, toEl) {
var curChild = fromEl.firstChild;
@ -1885,18 +1885,18 @@ webpackJsonp([2],[
}
var specialElHandlers = {
/**
* Needed for IE. Apparently IE doesn't think that "selected" is an
* attribute when reading over the attributes using selectEl.attributes
/**
* Needed for IE. Apparently IE doesn't think that "selected" is an
* attribute when reading over the attributes using selectEl.attributes
*/
OPTION: function OPTION(fromEl, toEl) {
syncBooleanAttrProp(fromEl, toEl, 'selected');
},
/**
* The "value" attribute is special for the <input> element since it sets
* the initial value. Changing the "value" attribute without changing the
* "value" property will have no effect since it is only used to the set the
* initial value. Similar for the "checked" attribute, and "disabled".
/**
* The "value" attribute is special for the <input> element since it sets
* the initial value. Changing the "value" attribute without changing the
* "value" property will have no effect since it is only used to the set the
* initial value. Similar for the "checked" attribute, and "disabled".
*/
INPUT: function INPUT(fromEl, toEl) {
syncBooleanAttrProp(fromEl, toEl, 'checked');
@ -2024,13 +2024,13 @@ webpackJsonp([2],[
}
}
/**
* Removes a DOM node out of the original DOM
*
* @param {Node} node The node to remove
* @param {Node} parentNode The nodes parent
* @param {Boolean} skipKeyedNodes If true then elements with keys will be skipped and not discarded.
* @return {undefined}
/**
* Removes a DOM node out of the original DOM
*
* @param {Node} node The node to remove
* @param {Node} parentNode The nodes parent
* @param {Boolean} skipKeyedNodes If true then elements with keys will be skipped and not discarded.
* @return {undefined}
*/
function removeNode(node, parentNode, skipKeyedNodes) {
if (onBeforeNodeDiscarded(node) === false) {
@ -2395,16 +2395,16 @@ webpackJsonp([2],[
Object.defineProperty(exports, "__esModule", {
value: true
});
/*
* html2json for omi
* https://github.com/AlloyTeam/omi
*
* Original code by John Resig (ejohn.org)
* http://ejohn.org/blog/pure-javascript-html-parser/
* Original code by Erik Arvidsson, Mozilla Public License
* http://erik.eae.net/simplehtmlparser/simplehtmlparser.js
* Original code by Jxck
* https://github.com/Jxck/html2json
/*
* html2json for omi
* https://github.com/AlloyTeam/omi
*
* Original code by John Resig (ejohn.org)
* http://ejohn.org/blog/pure-javascript-html-parser/
* Original code by Erik Arvidsson, Mozilla Public License
* http://erik.eae.net/simplehtmlparser/simplehtmlparser.js
* Original code by Jxck
* https://github.com/Jxck/html2json
*/
// Regular Expressions for parsing tags and attributes

View File

@ -0,0 +1,200 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // install a JSONP callback for chunk loading
/******/ var parentJsonpFunction = window["webpackJsonp"];
/******/ window["webpackJsonp"] = function webpackJsonpCallback(chunkIds, moreModules) {
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0, callbacks = [];
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
/******/ if(installedChunks[chunkId])
/******/ callbacks.push.apply(callbacks, installedChunks[chunkId]);
/******/ installedChunks[chunkId] = 0;
/******/ }
/******/ for(moduleId in moreModules) {
/******/ modules[moduleId] = moreModules[moduleId];
/******/ }
/******/ if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules);
/******/ while(callbacks.length)
/******/ callbacks.shift().call(null, __webpack_require__);
/******/ if(moreModules[0]) {
/******/ installedModules[0] = 0;
/******/ return __webpack_require__(0);
/******/ }
/******/ };
/******/ // The module cache
/******/ var installedModules = {};
/******/ // object to store loaded and loading chunks
/******/ // "0" means "already loaded"
/******/ // Array means "loading", array contains callbacks
/******/ var installedChunks = {
/******/ 3:0
/******/ };
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // This file contains only the entry chunk.
/******/ // The chunk loading function for additional chunks
/******/ __webpack_require__.e = function requireEnsure(chunkId, callback) {
/******/ // "0" is the signal for "already loaded"
/******/ if(installedChunks[chunkId] === 0)
/******/ return callback.call(null, __webpack_require__);
/******/ // an array means "currently loading".
/******/ if(installedChunks[chunkId] !== undefined) {
/******/ installedChunks[chunkId].push(callback);
/******/ } else {
/******/ // start chunk loading
/******/ installedChunks[chunkId] = [callback];
/******/ var head = document.getElementsByTagName('head')[0];
/******/ var script = document.createElement('script');
/******/ script.type = 'text/javascript';
/******/ script.charset = 'utf-8';
/******/ script.async = true;
/******/ script.src = __webpack_require__.p + "" + chunkId + "." + ({"0":"docs-cn","1":"docs-en","2":"omi"}[chunkId]||chunkId) + "." + {"0":"7d2017f1","1":"af7f09ce","2":"b9df77fe"}[chunkId] + ".js";
/******/ head.appendChild(script);
/******/ }
/******/ };
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ({
/***/ 0:
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(51);
/***/ },
/***/ 51:
/***/ function(module, exports) {
"use strict";
/*! @source http://purl.eligrey.com/github/classList.js/blob/master/classList.js */
"document" in self && ("classList" in document.createElement("_") && (!document.createElementNS || "classList" in document.createElementNS("http://www.w3.org/2000/svg", "g")) ? !function () {
"use strict";
var t = document.createElement("_");if (t.classList.add("c1", "c2"), !t.classList.contains("c2")) {
var e = function e(t) {
var e = DOMTokenList.prototype[t];DOMTokenList.prototype[t] = function (t) {
var n,
i = arguments.length;for (n = 0; i > n; n++) {
t = arguments[n], e.call(this, t);
}
};
};e("add"), e("remove");
}if (t.classList.toggle("c3", !1), t.classList.contains("c3")) {
var n = DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle = function (t, e) {
return 1 in arguments && !this.contains(t) == !e ? e : n.call(this, t);
};
}t = null;
}() : !function (t) {
"use strict";
if ("Element" in t) {
var e = "classList",
n = "prototype",
i = t.Element[n],
s = Object,
r = String[n].trim || function () {
return this.replace(/^\s+|\s+$/g, "");
},
o = Array[n].indexOf || function (t) {
for (var e = 0, n = this.length; n > e; e++) {
if (e in this && this[e] === t) return e;
}return -1;
},
c = function c(t, e) {
this.name = t, this.code = DOMException[t], this.message = e;
},
a = function a(t, e) {
if ("" === e) throw new c("SYNTAX_ERR", "An invalid or illegal string was specified");if (/\s/.test(e)) throw new c("INVALID_CHARACTER_ERR", "String contains an invalid character");return o.call(t, e);
},
l = function l(t) {
for (var e = r.call(t.getAttribute("class") || ""), n = e ? e.split(/\s+/) : [], i = 0, s = n.length; s > i; i++) {
this.push(n[i]);
}this._updateClassName = function () {
t.setAttribute("class", this.toString());
};
},
u = l[n] = [],
h = function h() {
return new l(this);
};if (c[n] = Error[n], u.item = function (t) {
return this[t] || null;
}, u.contains = function (t) {
return t += "", -1 !== a(this, t);
}, u.add = function () {
var t,
e = arguments,
n = 0,
i = e.length,
s = !1;do {
t = e[n] + "", -1 === a(this, t) && (this.push(t), s = !0);
} while (++n < i);s && this._updateClassName();
}, u.remove = function () {
var t,
e,
n = arguments,
i = 0,
s = n.length,
r = !1;do {
for (t = n[i] + "", e = a(this, t); -1 !== e;) {
this.splice(e, 1), r = !0, e = a(this, t);
}
} while (++i < s);r && this._updateClassName();
}, u.toggle = function (t, e) {
t += "";var n = this.contains(t),
i = n ? e !== !0 && "remove" : e !== !1 && "add";return i && this[i](t), e === !0 || e === !1 ? e : !n;
}, u.toString = function () {
return this.join(" ");
}, s.defineProperty) {
var f = { get: h, enumerable: !0, configurable: !0 };try {
s.defineProperty(i, e, f);
} catch (d) {
void 0 !== d.number && -2146823252 !== d.number || (f.enumerable = !1, s.defineProperty(i, e, f));
}
} else s[n].__defineGetter__ && i.__defineGetter__(e, h);
}
}(self));
/***/ }
/******/ });