@cycle/dom
Version:
The standard DOM Driver for Cycle.js, based on Snabbdom
49 lines • 1.48 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var snabbdom_1 = require("snabbdom");
function copyToThunk(vnode, thunkVNode) {
thunkVNode.elm = vnode.elm;
vnode.data.fn = thunkVNode.data.fn;
vnode.data.args = thunkVNode.data.args;
vnode.data.isolate = thunkVNode.data.isolate;
thunkVNode.data = vnode.data;
thunkVNode.children = vnode.children;
thunkVNode.text = vnode.text;
thunkVNode.elm = vnode.elm;
}
function init(thunkVNode) {
var cur = thunkVNode.data;
var vnode = cur.fn.apply(undefined, cur.args);
copyToThunk(vnode, thunkVNode);
}
function prepatch(oldVnode, thunkVNode) {
var old = oldVnode.data, cur = thunkVNode.data;
var i;
var oldArgs = old.args, args = cur.args;
if (old.fn !== cur.fn || oldArgs.length !== args.length) {
copyToThunk(cur.fn.apply(undefined, args), thunkVNode);
}
for (i = 0; i < args.length; ++i) {
if (oldArgs[i] !== args[i]) {
copyToThunk(cur.fn.apply(undefined, args), thunkVNode);
return;
}
}
copyToThunk(oldVnode, thunkVNode);
}
function thunk(sel, key, fn, args) {
if (args === undefined) {
args = fn;
fn = key;
key = undefined;
}
return snabbdom_1.h(sel, {
key: key,
hook: { init: init, prepatch: prepatch },
fn: fn,
args: args,
});
}
exports.thunk = thunk;
exports.default = thunk;
//# sourceMappingURL=thunk.js.map
;