UNPKG

@cycle/dom

Version:

The standard DOM Driver for Cycle.js, based on Snabbdom

46 lines 1.37 kB
import { h } from 'snabbdom'; function copyToThunk(vnode, thunkVNode) { thunkVNode.elm = vnode.elm; vnode.data.fn = thunkVNode.data.fn; vnode.data.args = thunkVNode.data.args; vnode.data.isolate = thunkVNode.data.isolate; thunkVNode.data = vnode.data; thunkVNode.children = vnode.children; thunkVNode.text = vnode.text; thunkVNode.elm = vnode.elm; } function init(thunkVNode) { var cur = thunkVNode.data; var vnode = cur.fn.apply(undefined, cur.args); copyToThunk(vnode, thunkVNode); } function prepatch(oldVnode, thunkVNode) { var old = oldVnode.data, cur = thunkVNode.data; var i; var oldArgs = old.args, args = cur.args; if (old.fn !== cur.fn || oldArgs.length !== args.length) { copyToThunk(cur.fn.apply(undefined, args), thunkVNode); } for (i = 0; i < args.length; ++i) { if (oldArgs[i] !== args[i]) { copyToThunk(cur.fn.apply(undefined, args), thunkVNode); return; } } copyToThunk(oldVnode, thunkVNode); } export function thunk(sel, key, fn, args) { if (args === undefined) { args = fn; fn = key; key = undefined; } return h(sel, { key: key, hook: { init: init, prepatch: prepatch }, fn: fn, args: args, }); } export default thunk; //# sourceMappingURL=thunk.js.map