omi v1.1.3 - fix dynamic child node problem

This commit is contained in:
dntzhang 2017-03-25 08:44:12 +08:00
parent a228d34ec8
commit 1dca2d17b5
15 changed files with 154 additions and 2066 deletions

53
dist/omi.js vendored
View File

@ -1,5 +1,5 @@
/*!
* Omi v1.1.2 By dntzhang
* Omi v1.1.3 By dntzhang
* Github: https://github.com/AlloyTeam/omi
* MIT Licensed.
*/
@ -1299,8 +1299,8 @@ return /******/ (function(modules) { // webpackBootstrap
this._generateHTMLCSS();
if (!isSelf) {
this._extractChildren(this);
} else if (_omi2['default'].customTags.length > 0) {
this.HTML = this._replaceTags(_omi2['default'].customTags, this.HTML);
} else {
this._extractChildrenString(this);
}
this.children.forEach(function (item) {
@ -1362,8 +1362,8 @@ return /******/ (function(modules) { // webpackBootstrap
this._generateHTMLCSS();
if (!isSelf) {
this._extractChildren(this);
} else if (_omi2['default'].customTags.length > 0) {
this.HTML = this._replaceTags(_omi2['default'].customTags, this.HTML);
} else {
this._extractChildrenString(this);
}
this.children.forEach(function (item) {
@ -1570,13 +1570,14 @@ return /******/ (function(modules) { // webpackBootstrap
return current;
}
}, {
key: '_extractChildren',
value: function _extractChildren(child) {
key: '_extractChildrenString',
value: function _extractChildrenString(child) {
var _this10 = this;
if (_omi2['default'].customTags.length > 0) {
child.HTML = this._replaceTags(_omi2['default'].customTags, child.HTML);
}
if (_omi2['default'].customTags.length === 0) return;
child.HTML = this._replaceTags(_omi2['default'].customTags, child.HTML);
var arr = child.HTML.match(/<child[^>][\s\S]*?tag=['|"](\S*)['|"][\s\S]*?><\/child>/g);
if (arr) {
@ -1586,6 +1587,30 @@ return /******/ (function(modules) { // webpackBootstrap
var name = attr.tag;
delete attr.tag;
var cmi = _this10.children[i];
if (cmi && cmi.___omi_constructor_name === name) {
cmi._omiChildStr = childStr;
}
});
}
}
}, {
key: '_extractChildren',
value: function _extractChildren(child) {
var _this11 = this;
if (_omi2['default'].customTags.length === 0) return;
child.HTML = this._replaceTags(_omi2['default'].customTags, child.HTML);
var arr = child.HTML.match(/<child[^>][\s\S]*?tag=['|"](\S*)['|"][\s\S]*?><\/child>/g);
if (arr) {
arr.forEach(function (childStr, i) {
var json = (0, _html2json2['default'])(childStr);
var attr = json.child[0].attr;
var name = attr.tag;
delete attr.tag;
var cmi = _this11.children[i];
//if not first time to invoke _extractChildren method
if (cmi && cmi.___omi_constructor_name === name) {
cmi._omiChildStr = childStr;
@ -1618,15 +1643,15 @@ return /******/ (function(modules) { // webpackBootstrap
child._omiGroupDataCounter[value] = 0;
}
groupDataIndex = child._omiGroupDataCounter[value];
dataset = _this10._extractPropertyFromString(value, child)[groupDataIndex];
dataset = _this11._extractPropertyFromString(value, child)[groupDataIndex];
} else if (key.indexOf('data-') === 0) {
dataset[_this10._capitalize(key.replace('data-', ''))] = value;
dataset[_this11._capitalize(key.replace('data-', ''))] = value;
} else if (key.indexOf(':data-') === 0) {
dataset[_this10._capitalize(key.replace(':data-', ''))] = eval('(' + value + ')');
dataset[_this11._capitalize(key.replace(':data-', ''))] = eval('(' + value + ')');
} else if (key === ':data') {
dataset = eval('(' + value + ')');
} else if (key === 'data') {
dataset = _this10._extractPropertyFromString(value, child);
dataset = _this11._extractPropertyFromString(value, child);
} else if (key === 'preventSelfUpdate' || key === 'psu') {
_omi_preventSelfUpdate = true;
} else if (key === 'selfDataFirst' || key === 'sdf') {

53
dist/omi.lite.js vendored
View File

@ -1,5 +1,5 @@
/*!
* Omi v1.1.2 By dntzhang
* Omi v1.1.3 By dntzhang
* Github: https://github.com/AlloyTeam/omi
* MIT Licensed.
*/
@ -683,8 +683,8 @@ return /******/ (function(modules) { // webpackBootstrap
this._generateHTMLCSS();
if (!isSelf) {
this._extractChildren(this);
} else if (_omi2['default'].customTags.length > 0) {
this.HTML = this._replaceTags(_omi2['default'].customTags, this.HTML);
} else {
this._extractChildrenString(this);
}
this.children.forEach(function (item) {
@ -746,8 +746,8 @@ return /******/ (function(modules) { // webpackBootstrap
this._generateHTMLCSS();
if (!isSelf) {
this._extractChildren(this);
} else if (_omi2['default'].customTags.length > 0) {
this.HTML = this._replaceTags(_omi2['default'].customTags, this.HTML);
} else {
this._extractChildrenString(this);
}
this.children.forEach(function (item) {
@ -954,13 +954,14 @@ return /******/ (function(modules) { // webpackBootstrap
return current;
}
}, {
key: '_extractChildren',
value: function _extractChildren(child) {
key: '_extractChildrenString',
value: function _extractChildrenString(child) {
var _this10 = this;
if (_omi2['default'].customTags.length > 0) {
child.HTML = this._replaceTags(_omi2['default'].customTags, child.HTML);
}
if (_omi2['default'].customTags.length === 0) return;
child.HTML = this._replaceTags(_omi2['default'].customTags, child.HTML);
var arr = child.HTML.match(/<child[^>][\s\S]*?tag=['|"](\S*)['|"][\s\S]*?><\/child>/g);
if (arr) {
@ -970,6 +971,30 @@ return /******/ (function(modules) { // webpackBootstrap
var name = attr.tag;
delete attr.tag;
var cmi = _this10.children[i];
if (cmi && cmi.___omi_constructor_name === name) {
cmi._omiChildStr = childStr;
}
});
}
}
}, {
key: '_extractChildren',
value: function _extractChildren(child) {
var _this11 = this;
if (_omi2['default'].customTags.length === 0) return;
child.HTML = this._replaceTags(_omi2['default'].customTags, child.HTML);
var arr = child.HTML.match(/<child[^>][\s\S]*?tag=['|"](\S*)['|"][\s\S]*?><\/child>/g);
if (arr) {
arr.forEach(function (childStr, i) {
var json = (0, _html2json2['default'])(childStr);
var attr = json.child[0].attr;
var name = attr.tag;
delete attr.tag;
var cmi = _this11.children[i];
//if not first time to invoke _extractChildren method
if (cmi && cmi.___omi_constructor_name === name) {
cmi._omiChildStr = childStr;
@ -1002,15 +1027,15 @@ return /******/ (function(modules) { // webpackBootstrap
child._omiGroupDataCounter[value] = 0;
}
groupDataIndex = child._omiGroupDataCounter[value];
dataset = _this10._extractPropertyFromString(value, child)[groupDataIndex];
dataset = _this11._extractPropertyFromString(value, child)[groupDataIndex];
} else if (key.indexOf('data-') === 0) {
dataset[_this10._capitalize(key.replace('data-', ''))] = value;
dataset[_this11._capitalize(key.replace('data-', ''))] = value;
} else if (key.indexOf(':data-') === 0) {
dataset[_this10._capitalize(key.replace(':data-', ''))] = eval('(' + value + ')');
dataset[_this11._capitalize(key.replace(':data-', ''))] = eval('(' + value + ')');
} else if (key === ':data') {
dataset = eval('(' + value + ')');
} else if (key === 'data') {
dataset = _this10._extractPropertyFromString(value, child);
dataset = _this11._extractPropertyFromString(value, child);
} else if (key === 'preventSelfUpdate' || key === 'psu') {
_omi_preventSelfUpdate = true;
} else if (key === 'selfDataFirst' || key === 'sdf') {

File diff suppressed because one or more lines are too long

6
dist/omi.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +0,0 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Omi</title>
</head>
<body>
<script src="bundler.js"></script>
</body>
</html>

View File

@ -1,39 +0,0 @@
import Omi from '../../../src/index.js';
import SubHello from './sub_hello.js';
import World from './world.js';
class Hello extends Omi.Component {
constructor(data) {
super(data);
}
style () {
return `
h1{
cursor:pointer;
}
`;
}
handleClick(dom){
alert(dom.innerHTML);
}
render() {
return `
<div>
<h1 onclick="handleClick(this)">Omi</h1>
<World omi-id="world" data-name="abcd" data-list='{"name":"Latch", "album":"Disclosure", "date":"2013"}' />
<div class="test">
Hello {{name}}!
<SubHello name="list" />
</div>
</div>
`;
}
}
Omi.makeHTML('Hello', Hello);
export default Hello;

View File

@ -1,28 +0,0 @@
import Omi from '../../../src/index.js';
import SubSubHello from './sub_sub_hello.js';
class SubHello extends Omi.Component {
constructor(data) {
super(data);
}
style(){
return`
a{
color: #4078c0;
text-decoration: none;
}
`;
}
render() {
return `
<div>
<a href="https://github.com/AlloyTeam/AlloyTouch/wiki/Scoped-CSS">link</a>
i am SubHello's instance2{{name}}!
<SubSubHello />
</div>
`;
}
}
Omi.makeHTML('SubHello', SubHello);
export default SubHello;

View File

@ -1,18 +0,0 @@
import Omi from '../../../src/index.js';
class SubSubHello extends Omi.Component {
constructor(data) {
super(data);
}
render() {
return `
<div>
i am SubSubHello's instance{{name}}!
</div>
`;
}
}
Omi.makeHTML('SubSubHello', SubSubHello);
export default SubSubHello;

View File

@ -1,18 +0,0 @@
import Omi from '../../../src/index.js';
class World extends Omi.Component {
constructor(data) {
super(data);
}
render() {
return `
<div>
i am World's instance2{{list}}!
</div>`;
}
}
Omi.makeHTML('World', World);
export default World;

View File

@ -1,23 +0,0 @@
import Hello from './js/hello.js';
import World from './js/world.js';
let hello = new Hello({ name:'Omi'});
Omi.render(hello,'body');
let world = new World({name:"abcd",list:'{"name":"Latch", "album":"Disclosure", "date":"2013"}'});
hello.addComponent("afterEnd",".test",world);
setTimeout(function(){
Omi.mapping["world"].data.list ="aa"
Omi.mapping["world"].update();
},1000);
setTimeout(function(){
hello.removeComponent(world);
},2000);
setTimeout(function(){
hello.addComponent("afterEnd",".test",world);
},3000);

View File

@ -1395,8 +1395,8 @@
this._generateHTMLCSS();
if (!isSelf) {
this._extractChildren(this);
} else if (_omi2['default'].customTags.length > 0) {
this.HTML = this._replaceTags(_omi2['default'].customTags, this.HTML);
} else {
this._extractChildrenString(this);
}
this.children.forEach(function (item) {
@ -1458,8 +1458,8 @@
this._generateHTMLCSS();
if (!isSelf) {
this._extractChildren(this);
} else if (_omi2['default'].customTags.length > 0) {
this.HTML = this._replaceTags(_omi2['default'].customTags, this.HTML);
} else {
this._extractChildrenString(this);
}
this.children.forEach(function (item) {
@ -1643,11 +1643,7 @@
}
});
Object.keys(baseData).forEach(function (key) {
_this9._dataset[key] = attr[key];
});
return this._dataset;
return Object.assign(baseData, this._dataset);
}
}, {
key: '_capitalize',
@ -1670,13 +1666,14 @@
return current;
}
}, {
key: '_extractChildren',
value: function _extractChildren(child) {
key: '_extractChildrenString',
value: function _extractChildrenString(child) {
var _this10 = this;
if (_omi2['default'].customTags.length > 0) {
child.HTML = this._replaceTags(_omi2['default'].customTags, child.HTML);
}
if (_omi2['default'].customTags.length === 0) return;
child.HTML = this._replaceTags(_omi2['default'].customTags, child.HTML);
var arr = child.HTML.match(/<child[^>][\s\S]*?tag=['|"](\S*)['|"][\s\S]*?><\/child>/g);
if (arr) {
@ -1686,6 +1683,30 @@
var name = attr.tag;
delete attr.tag;
var cmi = _this10.children[i];
if (cmi && cmi.___omi_constructor_name === name) {
cmi._omiChildStr = childStr;
}
});
}
}
}, {
key: '_extractChildren',
value: function _extractChildren(child) {
var _this11 = this;
if (_omi2['default'].customTags.length === 0) return;
child.HTML = this._replaceTags(_omi2['default'].customTags, child.HTML);
var arr = child.HTML.match(/<child[^>][\s\S]*?tag=['|"](\S*)['|"][\s\S]*?><\/child>/g);
if (arr) {
arr.forEach(function (childStr, i) {
var json = (0, _html2json2['default'])(childStr);
var attr = json.child[0].attr;
var name = attr.tag;
delete attr.tag;
var cmi = _this11.children[i];
//if not first time to invoke _extractChildren method
if (cmi && cmi.___omi_constructor_name === name) {
cmi._omiChildStr = childStr;
@ -1718,15 +1739,15 @@
child._omiGroupDataCounter[value] = 0;
}
groupDataIndex = child._omiGroupDataCounter[value];
dataset = _this10._extractPropertyFromString(value, child)[groupDataIndex];
dataset = _this11._extractPropertyFromString(value, child)[groupDataIndex];
} else if (key.indexOf('data-') === 0) {
dataset[_this10._capitalize(key.replace('data-', ''))] = value;
dataset[_this11._capitalize(key.replace('data-', ''))] = value;
} else if (key.indexOf(':data-') === 0) {
dataset[_this10._capitalize(key.replace(':data-', ''))] = eval('(' + value + ')');
dataset[_this11._capitalize(key.replace(':data-', ''))] = eval('(' + value + ')');
} else if (key === ':data') {
dataset = eval('(' + value + ')');
} else if (key === 'data') {
dataset = _this10._extractPropertyFromString(value, child);
dataset = _this11._extractPropertyFromString(value, child);
} else if (key === 'preventSelfUpdate' || key === 'psu') {
_omi_preventSelfUpdate = true;
} else if (key === 'selfDataFirst' || key === 'sdf') {
@ -2970,7 +2991,7 @@
_createClass(List, [{
key: 'render',
value: function render() {
return ' <div>\n <Test data-name="abc"/>\n <ul> {{#items}} <li>{{.}}</li> {{/items}}</ul>\n </div>';
return ' <div>\n <Test data-name="' + Math.random() + '"/>\n <ul> {{#items}} <li>{{.}}</li> {{/items}}</ul>\n </div>';
}
}]);

View File

@ -9,7 +9,7 @@ class List extends Omi.Component {
render () {
return ` <div>
<Test data-name="abc"/>
<Test data-name="${Math.random()}"/>
<ul> {{#items}} <li>{{.}}</li> {{/items}}</ul>
</div>`
}

View File

@ -1,6 +1,6 @@
{
"name": "omi",
"version": "1.1.2",
"version": "1.1.3",
"description": "Open and modern framework for building user interfaces.",
"main": "dist/omi.js",
"scripts": {

View File

@ -210,8 +210,8 @@ class Component {
this._generateHTMLCSS()
if(!isSelf) {
this._extractChildren(this)
}else if (Omi.customTags.length > 0) {
this.HTML = this._replaceTags(Omi.customTags, this.HTML)
}else {
this._extractChildrenString(this)
}
this.children.forEach(item => {
@ -269,8 +269,8 @@ class Component {
this._generateHTMLCSS()
if (!isSelf) {
this._extractChildren(this)
} else if (Omi.customTags.length > 0) {
this.HTML = this._replaceTags(Omi.customTags, this.HTML)
} else {
this._extractChildrenString(this)
}
this.children.forEach(item => {
@ -457,10 +457,32 @@ class Component {
}
_extractChildren(child){
if (Omi.customTags.length > 0) {
child.HTML = this._replaceTags(Omi.customTags, child.HTML)
_extractChildrenString(child){
if (Omi.customTags.length === 0) return
child.HTML = this._replaceTags(Omi.customTags, child.HTML)
let arr = child.HTML.match(/<child[^>][\s\S]*?tag=['|"](\S*)['|"][\s\S]*?><\/child>/g)
if(arr){
arr.forEach( (childStr, i) =>{
let json = html2json(childStr)
let attr = json.child[0].attr
let name = attr.tag
delete attr.tag
let cmi = this.children[i]
if (cmi && cmi.___omi_constructor_name === name) {
cmi._omiChildStr = childStr
}
})
}
}
_extractChildren(child){
if (Omi.customTags.length === 0) return
child.HTML = this._replaceTags(Omi.customTags, child.HTML)
let arr = child.HTML.match(/<child[^>][\s\S]*?tag=['|"](\S*)['|"][\s\S]*?><\/child>/g)
if(arr){