New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

clide

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clide

A thin layer over snabbdom.

latest
Source
npmnpm
Version
8.0.10
Version published
Weekly downloads
64
1180%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

virtual

FAQs

Package last updated on 21 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts