0.1.2 • Published 7 years ago
raj-snabbdom v0.1.2
Raj Snabbdom
npm install raj-snabbdomUsage
import { init, h } from 'snabbdom'
import { program, display } from 'raj-snabbdom'
import { runtime } from 'raj'
const patch = init(['with snabbdom modules'])
const render = display('div#root', patch)
const helloProgram = {
init: [{ text: 'hello world' }],
update: (msg, state) => [state],
view: (state, dispatch) => h('p', state.text)
}
const app = program(render, () => helloProgram)
runtime(app)Documentation
program(render, () => Program): Programrender: (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
program takes a render function and a function which returns a Raj program {init, update, view} and returns a new program, 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