UNPKG

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