1.0.1 • Published 8 years ago

most-vdom-adapter v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

API stability JavaScript Style Guide npm version

most-vdom-adapter

Experimental Most Adapter for vdoms

Get It

npm -i -S most-vdom-adapter

Usage

With snabbdom:

import {compose as compose2} from '@most/prelude'
import {drain} from 'most'
import adapter from 'most-vdom-adapter'

import snabbdom from 'snabbdom'
import events from 'snabbdom/modules/eventlisteners' 
import attrs from 'snabbdom/modules/attributes'
import clss from 'snabbdom/modules/class'
import h from 'snabbdom/h'

const compose = (...fns) = fns.reduce(compose2)
const tap = fn => s => s.tap(fn)
const map = fn => s => s.map(fn)
const take = n => s => s.take(n)
const log = console.log.bind(console)

const patch = snabbdom.init([events, attrs, clss])

const vnode = h('button.btn', {
  on: {
    'click': compose(drain, tap(log), take(4), map(event => event.target), adapter) 
  }
}, 'Really Cool Button')

patch(document.querySelector('.container'), vnode)

With inferno w/ createBlueprint:

import {compose as compose2} from '@most/prelude'
import {drain} from 'most'
import adapter from 'most-vdom-adapter'

import {createBlueprint} from 'inferno'
import {render} from 'inferno-dom'

const compose = (...fns) = fns.reduce(compose2)
const tap = fn => s => s.tap(fn)
const map = fn => s => s.map(fn)
const take = n => s => s.take(n)

const log = console.log.bind(console)

const reallyCoolBtn = createBlueprint({
    tag: 'button',
    attrs: {
        class: 'btn'
    },
    events: {
        arg: 0
    },
    children: {
        arg: 1
    }
})

render(reallyCoolBtn({
    onclick: compose(drain, tap(log), take(4), map(event => event.target), adapter) 
}, 'Let it Burn!'), document.querySelector('.container'))

Todo

  • add tests

Made with

@most/package-starter

1.0.1

8 years ago

1.0.0

8 years ago