0.5.0 • Published 7 years ago
ulmen-snabbdom v0.5.0
Ulmen Snabbdom
npm install ulmen-snabbdomUsage
import { init, h } from 'snabbdom'
import { snabbUlm, display } from 'ulmen-snabbdom'
import { ulmen } from 'ulmen'
const patch = init(['with snabbdom modules'])
const render = display('div#root', patch)
const helloUlm = {
init: { model: 'hello world' },
update: (msg, model) => ({ state }),
view: (model, dispatch) => h('p', model)
}
const ulm = snabbUlm(render, () => helloUlm)
ulmen(ulm).start()Documentation
snabbUlm(render, () => Ulm): Ulmrender: (view: VNode) => voidrender function which handles the virtual dom interactioninit: [state, effect?]initial State and optional effectupdate: (message, state) => [state,effect?]update function which returns new state and optional effectview: (state, dispatch) => VNodereturn the snabbdom view representation
snbbUlm takes a render function and a function which returns a ulm {init, update, view} and returns a new ulm, which updates the virtual dom when view is called
display(selector, patch): (view: VNode) => voidselectorthe dom selector of the root element (for example'div#root')patcha patch function created bysnabbdom.init()
display is an example implementation of a function which creates a render function. it holds internally the reference to oldNode