Skip to content

Commit

Permalink
Merge pull request #3 from oskarhane/add-reset
Browse files Browse the repository at this point in the history
Add reset function
  • Loading branch information
oskarhane authored Feb 13, 2017
2 parents 1aedc96 + dca87e7 commit 66fd803
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 205 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ response is Redux or single component state.
- [`one`](#one)
- [`send`](#send)
- [`self`](#self)
- [`reset`](#reset)

### Utility functions
- [`applyMiddleware`](#applyMiddleware)
Expand Down Expand Up @@ -198,6 +199,14 @@ subscriber to respond on. See tests file for an example.

#### Returns `void`

### <a id="reset"></a> `reset()`
Removes all subscribers on all channels.

#### Arguments
_No arguments_

#### Returns `void`

## Utility functions
Functions to configure or extend the bus.

Expand All @@ -213,7 +222,7 @@ Add middleware to Suber. All messages on all channels gets passed to the middlew
Removes all active all middlewares.

#### Arguments
- No arguments
_No arguments_

#### Returns `void`

Expand Down
3 changes: 2 additions & 1 deletion src/bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const wrapReduxMiddleware = (mw) => {
}

// Exposed bus methods
const reset = () => Object.keys(subscriptions).forEach((key) => delete subscriptions[key])
const take = (channel, fn, filterFn = null, once = false) => {
if (!channel || !fn) return false
return addChannelSubscriber(channel, fn, filterFn, once)
Expand All @@ -57,7 +58,7 @@ const _self = (channel, message, fn) => {
let nextId = 0
const subscriptions = {}
let middlewares = []
const bus = { take, one, send, self: _self }
const bus = { take, one, send, reset, self: _self }

// Exported functions
export const getBus = () => bus
Expand Down
Loading

0 comments on commit 66fd803

Please sign in to comment.