You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
785 B
JavaScript
34 lines
785 B
JavaScript
var h = require('./h');
|
|
|
|
function init(thunk) {
|
|
var i, cur = thunk.data;
|
|
cur.vnode = cur.fn.apply(undefined, cur.args);
|
|
}
|
|
|
|
function prepatch(oldThunk, thunk) {
|
|
var i, old = oldThunk.data, cur = thunk.data;
|
|
var oldArgs = old.args, args = cur.args;
|
|
cur.vnode = old.vnode;
|
|
if (oldArgs.length !== args.length) {
|
|
cur.vnode = cur.fn.apply(undefined, args);
|
|
return;
|
|
}
|
|
for (i = 0; i < args.length; ++i) {
|
|
if (oldArgs[i] !== args[i]) {
|
|
cur.vnode = cur.fn.apply(undefined, args);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = function(name, fn /* args */) {
|
|
var i, args = [];
|
|
for (i = 2; i < arguments.length; ++i) {
|
|
args[i - 2] = arguments[i];
|
|
}
|
|
return h('thunk' + name, {
|
|
hook: {init: init, prepatch: prepatch},
|
|
fn: fn, args: args,
|
|
});
|
|
};
|