Skip to content

hi-res/the-pivot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • CoffeeScript 100.0%