8.0.10 • Published 5 years ago

clide v8.0.10

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Clide

Clide is a simple render loop for snabbdom.

Installation

npm install clide

Usage

Example: A Simple Counter

import { init, h } from 'clide'
import sbEvents from 'snabbdom/modules/eventlisteners'

init([ sbEvents ])(counter)

function counter (lens) {
  const { count = 0 } = lens()
  return h('button', {
    on: {
      click: () => lens({ count: count + 1 })
    }
  }, count)
}

Example: Two Counters

import { init, h } from 'clide'
import sbEvents from 'snabbdom/modules/eventlisteners'

init([ sbEvents ])(app)

function app (lens) {
  return h('div', [
    counter(lens('one')),
    counter(lens('two'))
  ])
}

function counter (lens) {
  const { count = 0 } = lens()
  return h('button', {
    on: {
      click: () => lens({ count: count + 1 })
    }
  }, count)
}

Example: Many Counters

import { init, h } from 'clide'
import sbEvents from 'snabbdom/modules/eventlisteners'

init([ sbEvents ])(app)

function app (lens) {
  const { counters = [] } = lens()
  return h('div', [
    h('div', counters.map((_, idx) =>
      counter(lens('counters', idx)))),
    h('button', {
      on: {
        click: () => lens({ counters: counters.concat([ {} ]) })
      }
    }, '+')
  ])
}

function counter (lens) {
  const { count = 0 } = lens()
  return h('button', {
    on: {
      click: () => lens({ count: count + 1 })
    }
  }, count)
}

API

init(modules)

The init function takes an optional array of extra snabbdom modules to load and returns the render function. See the snabbdom init docs for more details about loading extra snabbdom modules.

render(view, options)

The render function is returned by init. This function should be called with a view function, and optionally an options object. The options object may contain the following properties:

PropertyDefaultDescription
state{}The initial state that should be returned by lens().
rootdocument.bodyThe DOM node to attach the view function to.

view(lens)

The view function is written by the developer, and should expect one argument: a lens from stateful-lens. This function must return a snabbdom virtual dom node. Updating the lens in this function will trigger a re-render. See the stateful-lens docs for more information.

8.0.10

5 years ago

8.0.8

6 years ago

8.0.7

6 years ago

8.0.6

6 years ago

8.0.5

6 years ago

8.0.2

6 years ago

8.0.0

6 years ago

7.1.9

6 years ago

7.1.8

6 years ago

7.1.7

6 years ago

7.1.6

6 years ago

7.1.5

7 years ago

7.1.4

7 years ago

7.1.3

7 years ago

7.1.2

7 years ago

7.1.1

7 years ago

7.1.0

7 years ago

7.0.0

7 years ago

6.6.0

7 years ago

6.5.0

7 years ago

6.4.0

7 years ago

6.3.0

7 years ago

6.2.0

7 years ago

6.1.0

7 years ago

6.0.8

7 years ago

6.0.7

7 years ago

6.0.6

7 years ago

6.0.5

7 years ago

6.0.4

7 years ago

6.0.3

7 years ago

6.0.2

7 years ago

5.1.0

7 years ago

5.0.5

7 years ago

5.0.4

7 years ago

5.0.3

7 years ago

5.0.1

7 years ago

5.0.0

7 years ago

4.1.0

7 years ago

4.0.0

7 years ago

0.2.9

7 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.0.1

7 years ago

3.0.0

7 years ago

2.0.0

7 years ago

1.0.0

7 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.0

11 years ago