dissemination
Lightweight event/command library created to replace Backbone.Radio in projects ported from Backbone/Marionette to React.
Installation
npm install dissemination --save
Usage
-
ES6:
; -
require with Node.js:
var dissemination = ; -
in browser include
dist/dissemination.js
ordist/dissemination.min.js
script:var dissemination = windowdissemination;
and then
;;
Examples
Channel
-
get default channel (with
application
name):const c = ; -
get named channel:
const c = ; -
create channel directly:
;const c = ;
Events
-
add event listener:
const listener = { console; };; -
remove specific event listener:
; -
remove all event listeners for a given event:
; -
fire event:
; -
fire event with parameters:
const listener = {console; // => { item: 1 }};;; -
add event listener with additional options:
const listener = {console; // => { item: 1 }console; // => { message: 'hello world' }};;; -
add event listener that will be executed once:
let count = 0;const listener = { count += 1; };;;;console; // => 1 -
interrupt event listeners' execution chain:
let result = 0;const listener1 = { result += 1; return false; };const listener2 = { result += 2; };;;;console; // => 1 -
check whether event listeners are registered:
const listener = { console; };;console; // => true
Commands
-
add command handler:
const handler = { console; };; -
remove specific command handler:
; -
execute command:
; -
execute command with response result:
const handler = { return 1 };;console; // => 1 -
add command handler with additional options:
const positive = optionsnumber >= 0;;console; // => trueconsole; // => false -
check whether command handler is registered:
const handler = { console; };;console; // => true
Mixins
-
add
EventMixin
or/andCommandMixin
to any custom object:;const events = Object;events;events;;const commands = Object;commands;console; // => 'hello world'
Building
In order to build library run:
npm run build
Testing
Run unit tests:
npm test
Run tests with coverage:
npm run test:coverage
In order to run tests with Coveralls locally you have to provide COVERALLS_REPO_TOKEN
:
COVERALLS_REPO_TOKEN=<token> npm run test:coverage
Contributing
Before making a pull request, please, be sure that you are starting from develop
branch.