Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed May 28, 2014
1 parent fdcaacf commit e2dbb4e
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ An event dispatcher for the [flux architecture](http://facebook.github.io/react/
npm i --save barracks
````

## API
## Usage
````js
/**
* Initialize barracks.
Expand All @@ -24,17 +24,41 @@ var dispatcher = Dispatcher();
*/

var callbackFunction = function(arg) {
console.log('I got triggered');
console.log(arg + ' got triggered');
};
dispatcher.register('eventName', callbackFunction);

/**
* Dispatch registered callbacks for 'eventName'.
*/

dispatcher.dispatch('eventName', 'Loki');
// -> 'Loki got triggered'
````

## API
#### .register()
Register a new object to the store. Takes a `{String} action` that determines the
message it should respond to, and a `{Function} callback` that executes the response.
````js
dispatcher.register('eventName', function(arg) {return arg});
dispatcher.register('otherEvent', function() {return 'hi')});
````

#### .dispatch()
Trigger all callbacks corresponding to `{String} action` and provide them an
argument of `{Mixed} data`.
````js
dispatcher.dispatch('eventName', 12);
// -> 12

dispatcher.dispatch('eventName');
// -> 'I got triggered'
// -> throw Error

dispatcher.dispatch('otherEvent', null);
// -> 'hi'
````


## License
[MIT](https://tldrlegal.com/license/mit-license) © [Yoshua Wuyts](yoshuawuyts.com)

0 comments on commit e2dbb4e

Please sign in to comment.