spirit-events v1.0.0
Spirit Events
A light weight event emitter for the Spirit Core static file generator.
Used to listen, remove and emit events from the spirit object .
Usage
install the Spirit Core module.
npm install spirit-core
The middleware will expose three Functions
on the spirit core Object
.
on
Takes two arguments a unique String
identifier and a 'Function' to call.
The callback will be called every time the unique String
identifier is emitted.
emit
Takes one argument a unique String
identifier.
Will call every Function
subscribed to that unique String
identifier through on.
off
Takes one argument a unique String
identifier, with on optional second Function
.
If only passed one argument, will remove all callbacks subscribed to the unique String
identifier.
If a Function
is passed it will only remove the Function
subscribed to the unique String
identifier.
Example
var spiritCore = require( 'spirit-core' ) ;
var someEvent = "SOME_EVENT" ;
spiritCore.on( someEvent, callback ) ;
spiritCore.emit( someEvent, "Hello ", "World" ) ;
function callback ( hello, world ) {
var helloWorld = hello + world ;
console.log( helloWorld ) ;
}