framework7
Version:
Full featured mobile HTML framework for building iOS & Android apps
66 lines (55 loc) • 1.3 kB
JavaScript
;
exports.__esModule = true;
exports.default = exports.thunk = void 0;
var _h = require("./h");
function copyToThunk(vnode, thunk) {
thunk.elm = vnode.elm;
vnode.data.fn = thunk.data.fn;
vnode.data.args = thunk.data.args;
thunk.data = vnode.data;
thunk.children = vnode.children;
thunk.text = vnode.text;
thunk.elm = vnode.elm;
}
function init(thunk) {
var cur = thunk.data;
var vnode = cur.fn.apply(undefined, cur.args);
copyToThunk(vnode, thunk);
}
function prepatch(oldVnode, thunk) {
var i,
old = oldVnode.data,
cur = thunk.data;
var oldArgs = old.args,
args = cur.args;
if (old.fn !== cur.fn || oldArgs.length !== args.length) {
copyToThunk(cur.fn.apply(undefined, args), thunk);
return;
}
for (i = 0; i < args.length; ++i) {
if (oldArgs[i] !== args[i]) {
copyToThunk(cur.fn.apply(undefined, args), thunk);
return;
}
}
copyToThunk(oldVnode, thunk);
}
var thunk = function thunk(sel, key, fn, args) {
if (args === undefined) {
args = fn;
fn = key;
key = undefined;
}
return (0, _h.h)(sel, {
key: key,
hook: {
init: init,
prepatch: prepatch
},
fn: fn,
args: args
});
};
exports.thunk = thunk;
var _default = thunk;
exports.default = _default;