1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var snabbdom_1 = require("snabbdom");
|
4 | function 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 | }
|
14 | function init(thunkVNode) {
|
15 | var cur = thunkVNode.data;
|
16 | var vnode = cur.fn.apply(undefined, cur.args);
|
17 | copyToThunk(vnode, thunkVNode);
|
18 | }
|
19 | function 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 | }
|
34 | function 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 | }
|
47 | exports.thunk = thunk;
|
48 | exports.default = thunk;
|
49 |
|
\ | No newline at end of file |