1 | "use strict";
|
2 | var h_1 = require("./h");
|
3 | function 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 | }
|
12 | function init(thunk) {
|
13 | var cur = thunk.data;
|
14 | var vnode = cur.fn.apply(undefined, cur.args);
|
15 | copyToThunk(vnode, thunk);
|
16 | }
|
17 | function 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 | }
|
31 | exports.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 | };
|
44 | Object.defineProperty(exports, "__esModule", { value: true });
|
45 | exports.default = exports.thunk;
|
46 |
|
\ | No newline at end of file |