0.0.2 • Published 7 years ago

reactive-data-unit v0.0.2

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

Reactive Data Unit

Simple ES6 Proxy-based store

Installation

npm install reactive-data-unit

Usage

import rdu from 'reactive-data-unit'

// create unit
const unit = rdu(1)

// add listener
const listener1 = unit((value) => {
  console.log(`listener1 logs ${value}`)
})
//> listener1 logs 1

// change value
unit.value = 2
//> listener1 logs 2

const listener2 = unit((value, initial) => {
  if (!initial) {
    // skip initial value
    console.log(`listener2 logs ${value}`)    
  }
})

unit.value++
//> listener1 logs 3
//> listener2 logs 3

// unbind listener
listener1.done()

unit.value--
//> listener2 logs 2

listener2.done()

unit.value++
//>