Simple event system and key->value storage
- Simple event system
- on( 'event', funktion ) # adds a listener
- off( 'event', funktion ) # removes a listener
- trigger( {} ) # triggers the listeners passing {} as argument
- Simple key-> value storage
- set( 'key', 'value' ) # stores a 'value'
- get( 'key' ) # retrieves a 'value'
- 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