the-pivot

0.2.2 • Public • Published

The Pivot

Simple event system and key->value storage

Build Status Coverage Status Dependency Status

Main concept

  1. Simple event system
  • on( 'event', funktion ) # adds a listener
  • off( 'event', funktion ) # removes a listener
  • trigger( {} ) # triggers the listeners passing {} as argument
  1. Simple key-> value storage
  • set( 'key', 'value' ) # stores a 'value'
  • get( 'key' ) # retrieves a 'value'
  1. Simple binding
  • bind( 'key', funktion ) # funktion will be called instantly and when the value changes

# create an instance of pivot

Pivot = require 'app/components/events/pivot'

pivot = new Pivot



# Store and Retrieve a value

pivot.set 'name', 'foo'
pivot.get 'name' 			# should be foo



# Listening and unlistening to an event

set_name = ( name ) -> console.log "set_name is #{name}"

pivot.on 'changed:name', set_name

pivot.trigger 'changed:name', 'foo'

pivot.off 'changed:name', set_name



# Using binds

pivot.set 'name', 'hems'

set_name = ( name ) -> console.log "got name #{name}"

pivot.bind 'name', set_name # will trigger intantly and when this value change

pivot.set 'name', 'hems' # won't trigger cause its a repeated value

pivot.set 'name', 'david' # triggers!



##WIP



# Using the listener object itself

listener = pivot.on 'name', ( name )

set_name = ( name ) -> console.log "set_name is #{name}"

listener = pivot.on 'changed:name', set_name  # will set name to hems and propagate

listener.trigger 'foo'

listener.off()



# include / extend

Readme

Keywords

none

Package Sidebar

Install

npm i the-pivot

Weekly Downloads

0

Version

0.2.2

License

none

Last publish

Collaborators

  • hems