Skip to content

fwilkerson/event-driven

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Event Driven

Helper functions for writing event driven systems.

 

EventEmitter

Subscribe to and publish events.

on(eventName, handler)

Subscribe an event handler

Parameters
Name Type Description
eventName string The name of the event
handler Function The function to be executed when the event is emitted
Returns
  • Function Returns the handler for easy unsubscription

remove(eventName, handler)

Unsubscribe an event handler

Parameters
Name Type Description
eventName string The name of the event
handler Function The handler to be removed
Returns
  • Void

emit(eventName, event)

Publish an event

Parameters
Name Type Description
eventName string The name of the event
event Object The parameter to pass to the event handlers
Returns
  • Void

 

Collection

A list that can have a handler(s) invoked any time the list is modified.

Collection(init)

The collection constructor with an optional initial value parameter

Parameters
Name Type Description
init Array An array to initialize the collection with
Returns
  • Collection<T> Returns the new collection

onCollectionChanged(handler)

Subscribe an event handler to be called whenever the collection is modified

Parameters
Name Type Description
handler Function The collection changed handler
Returns
  • Function Returns a function that when executed will remove the collection changed handler

add(value)

Add a value to the collection

Parameters
Name Type Description
value T The value to be added to the collection
Returns
  • Void

addRange(values)

Add a range of values to the collection

Parameters
Name Type Description
values Array The range of values to be added to the collection
Returns
  • Void

remove(value)

Remove the value from the collection

Parameters
Name Type Description
value T The value to be removed from the collection
Returns
  • Void

clear()

Removes all items within the collection

Returns
  • Void

toList()

Returns a copy of the list in the form of an array

Returns
  • Array<T> A copy of the collection

About

Helper functions for writing event driven systems

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published