Socket
Book a DemoInstallSign in
Socket

obzervable

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

obzervable

![build status](https://travis-ci.org/voodoo-child/obzervable.svg?branch=master)

0.1.4
latest
Source
npmnpm
Version published
Weekly downloads
7
600%
Maintainers
1
Weekly downloads
 
Created
Source

obzervable

build status

obzervable is a library for creating observable mutable states.

  • Works with nested objects and array mutators.
  • Supports mapping of states that allows to listen only to changes of certain properties of the state.
  • Can be used to do DOM Manipulations only when they are required.

Documentation

Documentation and usage examples: documentation

Example

Counter

import { createState, observe } from 'obzervable'

const State = createState( {
	count: 0,
	active: false
} )

const Counter = document.createElement( 'h1' )
const StartButton = document.createElement('button')
const ResetButton = document.createElement('button')
const Body = document.getElementsByTagName('body')[0]

ResetButton.innerText = 'reset'
Body.appendChild( Counter )
Body.appendChild( StartButton )
Body.appendChild( ResetButton )

const mapCount = ( { count } ) => ( { count } )
const mapActive = ( { active } ) => ( { active } )

observe( State, mapCount )( ( { count } ) => {
	return Counter.innerText = count
} );

( ( interval ) => {

	observe( State, mapActive )( ( { active } ) => {

		if ( active ) {
			interval = setInterval( () => State.count += 1, 1000)
		} else {
			clearInterval( interval )
		}

		StartButton.innerText = ( active ) ? 'stop' : 'start'

		return Counter.style.color = ( active ) ? 'green' : 'red'

	} )

} )( null )

StartButton.addEventListener( 'click', ( e ) => {
	const { active } = State
	State.active = !active
} )

ResetButton.addEventListener( 'click', ( e ) => {
	State.apply( {
		count: 0,
		active: false
	} )
} )

FAQs

Package last updated on 29 Nov 2018

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.