UNPKG

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