bug fixed vnode update bug & event update bug

This commit is contained in:
akira-cn 2018-12-11 15:00:59 +08:00
parent a17c91f898
commit 1d4869c225
6 changed files with 26 additions and 13 deletions

View File

@ -235,6 +235,7 @@ function updateEvents(oldVnode, vnode) {
oldVnode.elm.removeEventListener(type, f);
});
oldVnode.events = [];
}
if (vnode.elm && attrs) {
Object.entries(attrs).forEach(function (_ref3) {
@ -243,9 +244,10 @@ function updateEvents(oldVnode, vnode) {
val = _ref4[1];
if (key.indexOf('on') === 0 && typeof val === 'function') {
vnode.elm.addEventListener(key.slice(2).toLowerCase(), val);
var eventType = key.slice(2).toLowerCase();
vnode.elm.addEventListener(eventType, val);
vnode.events = vnode.events || [];
vnode.events.push([key, val]);
vnode.events.push([eventType, val]);
delete attrs[key];
}
});
@ -336,7 +338,9 @@ function render(scene, children) {
children.forEach(function (layer) {
if (!layer.attributes.id) layer.attributes.id = 'layer_' + Math.random().toString(36).slice(2);
var layerEl = scene.layer(layer.attributes.id);
patch(layerEl, parseVNode(layer));
var node = layerEl.vnode_ || layerEl;
layerEl.vnode_ = parseVNode(layer);
patch(node, layerEl.vnode_);
});
}

File diff suppressed because one or more lines are too long

View File

@ -4198,7 +4198,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = _class.__proto__ || Object.getPrototypeOf(_class)).call.apply(_ref, [this].concat(args))), _this), _this.data = {
scale: 0.5
}, _this.onClick = function (evt) {
// console.log(evt)
console.log(evt);
_this.data.scale = 0.5 + Math.random() * 0.1;
}, _temp), _possibleConstructorReturn(_this, _ret);
}
@ -4335,6 +4335,7 @@ function updateEvents(oldVnode, vnode) {
oldVnode.elm.removeEventListener(type, f);
});
oldVnode.events = [];
}
if (vnode.elm && attrs) {
Object.entries(attrs).forEach(function (_ref3) {
@ -4343,9 +4344,10 @@ function updateEvents(oldVnode, vnode) {
val = _ref4[1];
if (key.indexOf('on') === 0 && typeof val === 'function') {
vnode.elm.addEventListener(key.slice(2).toLowerCase(), val);
var eventType = key.slice(2).toLowerCase();
vnode.elm.addEventListener(eventType, val);
vnode.events = vnode.events || [];
vnode.events.push([key, val]);
vnode.events.push([eventType, val]);
delete attrs[key];
}
});
@ -4436,7 +4438,9 @@ function render(scene, children) {
children.forEach(function (layer) {
if (!layer.attributes.id) layer.attributes.id = 'layer_' + Math.random().toString(36).slice(2);
var layerEl = scene.layer(layer.attributes.id);
patch(layerEl, parseVNode(layer));
var node = layerEl.vnode_ || layerEl;
layerEl.vnode_ = parseVNode(layer);
patch(node, layerEl.vnode_);
});
}

View File

@ -32,7 +32,7 @@ define('my-app', class extends WeElement {
}
onClick = (evt) => {
// console.log(evt)
console.log(evt)
this.data.scale = 0.5 + Math.random() * 0.1
}

View File

@ -8,7 +8,8 @@
"lazy": "webpack -w",
"simple": "webpack -w",
"build": "webpack",
"build-min": "webpack"
"build-min": "webpack",
"prepublishOnly": "npm run build && npm run build-min"
},
"repository": {
"type": "git",

View File

@ -18,13 +18,15 @@ function updateEvents(oldVnode, vnode) {
oldEvents.forEach(([type, f]) => {
oldVnode.elm.removeEventListener(type, f)
})
oldVnode.events = []
}
if(vnode.elm && attrs) {
Object.entries(attrs).forEach(([key, val]) => {
if(key.indexOf('on') === 0 && typeof val === 'function') {
vnode.elm.addEventListener(key.slice(2).toLowerCase(), val)
const eventType = key.slice(2).toLowerCase()
vnode.elm.addEventListener(eventType, val)
vnode.events = vnode.events || []
vnode.events.push([key, val])
vnode.events.push([eventType, val])
delete attrs[key]
}
})
@ -98,6 +100,8 @@ function render(scene, children) {
children.forEach((layer) => {
if(!layer.attributes.id) layer.attributes.id = `layer_${Math.random().toString(36).slice(2)}`
const layerEl = scene.layer(layer.attributes.id)
patch(layerEl, parseVNode(layer))
const node = layerEl.vnode_ || layerEl
layerEl.vnode_ = parseVNode(layer)
patch(node, layerEl.vnode_)
})
}