Skip to content

Commit

Permalink
Docs: improve on docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoborus committed May 30, 2016
1 parent 0f69e33 commit aeafb41
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,19 @@ emitter.emit(obj)
## Emitter API

<a name="emitter-on-api"></a>
### on(key, action)
### on(eventKey, listener)

Adds the listener `action` to the `Set` for the event tagged with `key`.
`key` can be any type of value.
Adds the `listener` function to the end of the listeners array for the event tagged with `key`. A check is made to see if the listener has already been added so it won't be called multiple times. Event listeners are invoked in the order they are added.

`on` returns removeListener method
`on` returns removeListener method

```js
const obj = {}
let removeListener = emitter.on(obj, () => doSomething())
emitter.emit(obj) // will `doSomething`
emitter.emit(obj) // will `doSomething`
const key = {}
let removeListener = emitter.on(key, () => doSomething())
emitter.emit(key) // will `doSomething`
emitter.emit(key) // will `doSomething`
removeListener()
emitter.emit(obj) // won't do anything
emitter.emit(key) // won't do anything
```


Expand Down

0 comments on commit aeafb41

Please sign in to comment.