cycle-storage-most-driver

0.0.2 • Public • Published

This is a driver for all your pure-most Cycle apps (think Motorcycle) that needs a router only for the client.

Install

npm install --save cycle-storage-most-driver

Use

import most from 'most'
import Cycle from '@cycle/most-run'
import {makeDOMDriver, h} from '@motorcycle/dom'
import {makeStorageDriver} from 'cycle-storage-most-driver'

Cycle.run(app, {
  DOM: makeDOMDriver('#container', [
    require('snabbdom/modules/props'),
    require('snabbdom/modules/style')
  ]),
  STORAGE: makeStorageDriver(window.sessionStorage)
})

function app ({DOM, STORAGE}) {
  let vtree$ = STORAGE.all$
    .map(storage =>
      h('div', [
        h('span', `key 'somekey' has value ${storage['somekey']} stored.`),
        h('form', [
          h('input'),
          h('button', `set value at 'somekey`)
        ])
      ])
    )

  return {
    DOM: vtree$,
    STORAGE: DOM.select('form').events('submit')
      .tap(e => e.preventDefault())
      .map(e => ({
        'somekey': e.target.querySelector('input').value
      }))
  }
}

Package Sidebar

Install

npm i cycle-storage-most-driver

Weekly Downloads

0

Version

0.0.2

License

MIT

Last publish

Collaborators

  • fiatjaf