semi-working bundle
This commit is contained in:
parent
41cfda2719
commit
5265697cb2
20 changed files with 1391 additions and 123 deletions
|
|
@ -2,9 +2,12 @@
|
|||
|
||||
var Node = require("../render/node")
|
||||
|
||||
module.exports = function($window, onevent) {
|
||||
module.exports = function($window) {
|
||||
var $doc = $window.document
|
||||
|
||||
var onevent
|
||||
function setEventCallback(callback) {return onevent = callback}
|
||||
|
||||
//create
|
||||
function createNodes(parent, vnodes, start, end, hooks, nextSibling) {
|
||||
for (var i = start; i < end; i++) {
|
||||
|
|
@ -16,10 +19,7 @@ module.exports = function($window, onevent) {
|
|||
}
|
||||
function createNode(vnode, hooks) {
|
||||
var tag = vnode.tag
|
||||
if (vnode.attrs) {
|
||||
if (vnode.attrs.oninit) vnode.attrs.oninit.call(vnode, vnode)
|
||||
if (vnode.attrs.oncreate) hooks.push(vnode.attrs.oncreate.bind(vnode, vnode))
|
||||
}
|
||||
if (vnode.attrs != null) initLifecycle(vnode.attrs, vnode, hooks)
|
||||
if (typeof tag === "string") {
|
||||
switch (tag) {
|
||||
case "#": return createText(vnode)
|
||||
|
|
@ -324,8 +324,8 @@ module.exports = function($window, onevent) {
|
|||
}
|
||||
}
|
||||
function onremove(vnode) {
|
||||
if (vnode.attrs && vnode.attrs.onremove) vnode.attrs.onremove.call(vnode, vnode)
|
||||
if (typeof vnode.tag !== "string" && vnode.tag.onremove) vnode.tag.onremove.call(vnode, vnode)
|
||||
if (vnode.attrs && vnode.attrs.onremove) vnode.attrs.onremove.call(vnode.state, vnode)
|
||||
if (typeof vnode.tag !== "string" && vnode.tag.onremove) vnode.tag.onremove.call(vnode.state, vnode)
|
||||
|
||||
var children = vnode.children
|
||||
if (children instanceof Array) {
|
||||
|
|
@ -429,17 +429,17 @@ module.exports = function($window, onevent) {
|
|||
|
||||
//lifecycle
|
||||
function initLifecycle(source, vnode, hooks) {
|
||||
if (source.oninit != null) source.oninit.call(vnode, vnode)
|
||||
if (source.oncreate != null) hooks.push(source.oncreate.bind(vnode, vnode))
|
||||
if (source.oninit != null) source.oninit.call(vnode.state, vnode)
|
||||
if (source.oncreate != null) hooks.push(source.oncreate.bind(vnode.state, vnode))
|
||||
}
|
||||
function updateLifecycle(source, vnode, hooks, recycling) {
|
||||
if (recycling) initLifecycle(source, vnode, hooks)
|
||||
else if (source.onupdate != null) hooks.push(source.onupdate.bind(vnode, vnode))
|
||||
else if (source.onupdate != null) hooks.push(source.onupdate.bind(vnode.state, vnode))
|
||||
}
|
||||
function shouldUpdate(vnode, old) {
|
||||
var forceVnodeUpdate, forceComponentUpdate
|
||||
if (vnode.attrs != null && typeof vnode.attrs.shouldUpdate === "function") forceVnodeUpdate = vnode.attrs.shouldUpdate(vnode, old)
|
||||
if (typeof vnode.tag !== "string" && typeof vnode.tag.shouldUpdate === "function") forceComponentUpdate = vnode.tag.shouldUpdate(vnode, old)
|
||||
if (vnode.attrs != null && typeof vnode.attrs.shouldUpdate === "function") forceVnodeUpdate = vnode.attrs.shouldUpdate.call(vnode.state, vnode, old)
|
||||
if (typeof vnode.tag !== "string" && typeof vnode.tag.shouldUpdate === "function") forceComponentUpdate = vnode.tag.shouldUpdate.call(vnode.state, vnode, old)
|
||||
if (!(forceVnodeUpdate === undefined && forceComponentUpdate === undefined) && !forceVnodeUpdate && !forceComponentUpdate) {
|
||||
vnode.dom = old.dom
|
||||
vnode.domSize = old.domSize
|
||||
|
|
@ -460,6 +460,6 @@ module.exports = function($window, onevent) {
|
|||
dom.vnodes = vnodes
|
||||
if ($doc.activeElement !== active) active.focus()
|
||||
}
|
||||
|
||||
return {render: render}
|
||||
|
||||
return {render: render, setEventCallback: setEventCallback}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue