UNPKG

1.34 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var h_1 = require("./h");
4function copyToThunk(vnode, thunk) {
5 thunk.elm = vnode.elm;
6 vnode.data.fn = thunk.data.fn;
7 vnode.data.args = thunk.data.args;
8 thunk.data = vnode.data;
9 thunk.children = vnode.children;
10 thunk.text = vnode.text;
11 thunk.elm = vnode.elm;
12}
13function init(thunk) {
14 var cur = thunk.data;
15 var vnode = cur.fn.apply(undefined, cur.args);
16 copyToThunk(vnode, thunk);
17}
18function prepatch(oldVnode, thunk) {
19 var i, old = oldVnode.data, cur = thunk.data;
20 var oldArgs = old.args, args = cur.args;
21 if (old.fn !== cur.fn || oldArgs.length !== args.length) {
22 copyToThunk(cur.fn.apply(undefined, args), thunk);
23 return;
24 }
25 for (i = 0; i < args.length; ++i) {
26 if (oldArgs[i] !== args[i]) {
27 copyToThunk(cur.fn.apply(undefined, args), thunk);
28 return;
29 }
30 }
31 copyToThunk(oldVnode, thunk);
32}
33exports.thunk = function thunk(sel, key, fn, args) {
34 if (args === undefined) {
35 args = fn;
36 fn = key;
37 key = undefined;
38 }
39 return h_1.h(sel, {
40 key: key,
41 hook: { init: init, prepatch: prepatch },
42 fn: fn,
43 args: args
44 });
45};
46exports.default = exports.thunk;
47//# sourceMappingURL=thunk.js.map
\No newline at end of file