<commit_before># dissemination

[![NPM Version](https://badge.fury.io/js/dissemination.svg)](https://badge.fury.io/js/dissemination)
[![Build Status](https://travis-ci.org/ezze/dissemination.svg?branch=dev)](https://travis-ci.org/ezze/dissemination)
[![Coverage Status](https://coveralls.io/repos/github/ezze/dissemination/badge.svg?branch=dev)](https://coveralls.io/github/ezze/dissemination?branch=dev)

Lightweight event/command library created to replace [Backbone.Radio](https://github.com/marionettejs/backbone.radio) in
projects ported from [Backbone](http://backbonejs.org/)/[Marionette](https://marionettejs.com/) to [React](https://facebook.github.io/react/).

## Installation

```bash
npm install dissemination --save
```
    
## Usage

- require with Node.js:

    ```javascript
    var channel = require('dissemination');
    ```

- in browser include `dist/dissemination.js` or `dist/dissemination.min.js` script:

    ```javascript
    var channel = window.dissemination;
    ```
    
and then    
    
```javascript    
channel().on('event', function() { console.log('event is fired'); });
channel().fire('event');
```

## Examples

### Channel

- get default channel (with `application` name):

    ```javascript
    var c = channel();
    ```
    
- get named channel:

    ```javascript
    var c = channel('myChannel');
    ```
    
### Events
    
- add event listener:

    ```javascript
    var listener = function() { console.log('event is fired'); };
    channel().on('event', listener);
    ```    
    
- remove specific event listener:
    
    ```javascript
    channel().off('event', listener);
    ```
    
- remove all event listeners for a given event:
    
    ```javascript
    channel().off('event');
    ```
    
- fire event:

    ```javascript
    channel().fire('event');
    ```
    
- fire event with parameters:
    
    ```javascript
    var listener = function(name, params) {
        console.log(name); // => 'event'
        console.log(params); // => { item: 1 }
    };
    channel().on('event', listener);
    channel().fire('event', { item: 1 });
    ```
    
- add event listener with additional options:
    
    ```javascript
    var listener = function(name, params, options) {
        console.log(name); // => 'event'
        console.log(params); // => { item: 1 }
        console.log(options); // => { message: 'hello world' }
    };
    channel().on('event', listener, {
        message: 'hello world'      
    });
    channel().fire('event', { item: 1 });    
    ```
    
- add event listener that will be executed once:

    ```javascript
    var count = 0;
    var listener = function() { count += 1; };
    channel().once('event', listener);
    channel().fire('event');
    channel().fire('event');
    console.log(count); // => 1
    ```
    
- interrupt event listeners' execution chain:
    
    ```javascript
    var result = 0;
    var listener1 = function() { result += 1; return false; };
    var listener2 = function() { result += 2; };
    channel().on('event', listener1);
    channel().on('event', listener2);
    channel().fire('event');
    console.log(result); // => 1
    ```
    
- check whether event listeners are registered:

    ```javascript
    var listener = function() { console.log('event is fired'); };
    channel().on('event', listener);
    console.log(channel().listenersRegistered('event')); // => true
    ```
    
### Commands
    
- add command handler:

    ```javascript
    var handler = function() { console.log('command is handled'); };
    channel().handle('command', handler);
    ```
    
- remove specific command handler:
    
    ```javascript
    channel().unhandle('command');
    ```
    
- execute command:

    ```javascript
    channel().execute('command');
    ```
    
- execute command with response result:
    
    ```javascript
    var handler = function() { return 1 };
    channel().handle('command', handler);
    console.log(channel().request('command')); // => 1
    ```
    
- add command handler with additional options:    
    
    ```javascript
    var positive = function(options) {
        return options.number >= 0;
    };
    channel().handle('positive', positive);
    console.log(channel().request('positive', { number: 2 })); // => true
    console.log(channel().request('positive', { number: -1 })); // => false
    ```
    
- check whether command handler is registered:

    ```javascript
    var handler = function() { console.log('command is handled'); };
    channel().handle('command', handler);
    console.log(channel().handlerRegistered('command')); // => true
    ```    
    
### Mixins

- add `EventMixin` or/and `CommandMixin` to any custom object:

    ```javascript
    var events = Object.assign({}, channel.EventMixin);
    events.on('event', function({ console.log('event is fired'); }));
    events.fire('event');
    ```
    
    ```javascript
    var commands = Object.assign({}, channel.CommandMixin);
    commands.handle('command', function({ return 'hello world'; }));
    console.log(commands.request('command')); // => 'hello world'
    ```

## Building

In order to build library run:
                                          
    npm run build
    
## Testing
    
Run unit tests:
    
    npm test
    
In order to run tests with [Coveralls](http://coveralls.io) locally you have to provide `COVERALLS_REPO_TOKEN`:
        
    COVERALLS_REPO_TOKEN=<token> npm run test:coverage
    
## Contribution
    
Before making a pull request, please, be sure that your changes are rebased to `dev` branch.

## License

[MIT](LICENSE)<commit_msg>Code errors are fixed in README.md.<commit_after># dissemination

[![NPM Version](https://badge.fury.io/js/dissemination.svg)](https://badge.fury.io/js/dissemination)
[![Build Status](https://travis-ci.org/ezze/dissemination.svg?branch=dev)](https://travis-ci.org/ezze/dissemination)
[![Coverage Status](https://coveralls.io/repos/github/ezze/dissemination/badge.svg?branch=dev)](https://coveralls.io/github/ezze/dissemination?branch=dev)

Lightweight event/command library created to replace [Backbone.Radio](https://github.com/marionettejs/backbone.radio) in
projects ported from [Backbone](http://backbonejs.org/)/[Marionette](https://marionettejs.com/) to [React](https://facebook.github.io/react/).

## Installation

```bash
npm install dissemination --save
```
    
## Usage

- require with Node.js:

    ```javascript
    var channel = require('dissemination');
    ```

- in browser include `dist/dissemination.js` or `dist/dissemination.min.js` script:

    ```javascript
    var channel = window.dissemination;
    ```
    
and then    
    
```javascript    
channel().on('event', function() { console.log('event is fired'); });
channel().fire('event');
```

## Examples

### Channel

- get default channel (with `application` name):

    ```javascript
    var c = channel();
    ```
    
- get named channel:

    ```javascript
    var c = channel('myChannel');
    ```
    
### Events
    
- add event listener:

    ```javascript
    var listener = function() { console.log('event is fired'); };
    channel().on('event', listener);
    ```    
    
- remove specific event listener:
    
    ```javascript
    channel().off('event', listener);
    ```
    
- remove all event listeners for a given event:
    
    ```javascript
    channel().off('event');
    ```
    
- fire event:

    ```javascript
    channel().fire('event');
    ```
    
- fire event with parameters:
    
    ```javascript
    var listener = function(name, params) {
        console.log(name); // => 'event'
        console.log(params); // => { item: 1 }
    };
    channel().on('event', listener);
    channel().fire('event', { item: 1 });
    ```
    
- add event listener with additional options:
    
    ```javascript
    var listener = function(name, params, options) {
        console.log(name); // => 'event'
        console.log(params); // => { item: 1 }
        console.log(options); // => { message: 'hello world' }
    };
    channel().on('event', listener, {
        message: 'hello world'      
    });
    channel().fire('event', { item: 1 });    
    ```
    
- add event listener that will be executed once:

    ```javascript
    var count = 0;
    var listener = function() { count += 1; };
    channel().once('event', listener);
    channel().fire('event');
    channel().fire('event');
    console.log(count); // => 1
    ```
    
- interrupt event listeners' execution chain:
    
    ```javascript
    var result = 0;
    var listener1 = function() { result += 1; return false; };
    var listener2 = function() { result += 2; };
    channel().on('event', listener1);
    channel().on('event', listener2);
    channel().fire('event');
    console.log(result); // => 1
    ```
    
- check whether event listeners are registered:

    ```javascript
    var listener = function() { console.log('event is fired'); };
    channel().on('event', listener);
    console.log(channel().listenersRegistered('event')); // => true
    ```
    
### Commands
    
- add command handler:

    ```javascript
    var handler = function() { console.log('command is handled'); };
    channel().handle('command', handler);
    ```
    
- remove specific command handler:
    
    ```javascript
    channel().unhandle('command');
    ```
    
- execute command:

    ```javascript
    channel().execute('command');
    ```
    
- execute command with response result:
    
    ```javascript
    var handler = function() { return 1 };
    channel().handle('command', handler);
    console.log(channel().request('command')); // => 1
    ```
    
- add command handler with additional options:    
    
    ```javascript
    var positive = function(options) {
        return options.number >= 0;
    };
    channel().handle('positive', positive);
    console.log(channel().request('positive', { number: 2 })); // => true
    console.log(channel().request('positive', { number: -1 })); // => false
    ```
    
- check whether command handler is registered:

    ```javascript
    var handler = function() { console.log('command is handled'); };
    channel().handle('command', handler);
    console.log(channel().handlerRegistered('command')); // => true
    ```    
    
### Mixins

- add `EventMixin` or/and `CommandMixin` to any custom object:

    ```javascript
    var events = Object.assign({}, channel.EventMixin);
    events.on('event', function() { console.log('event is fired'); });
    events.fire('event');
    ```
    
    ```javascript
    var commands = Object.assign({}, channel.CommandMixin);
    commands.handle('command', function() { return 'hello world'; });
    console.log(commands.request('command')); // => 'hello world'
    ```

## Building

In order to build library run:
                                          
    npm run build
    
## Testing
    
Run unit tests:
    
    npm test
    
In order to run tests with [Coveralls](http://coveralls.io) locally you have to provide `COVERALLS_REPO_TOKEN`:
        
    COVERALLS_REPO_TOKEN=<token> npm run test:coverage
    
## Contribution
    
Before making a pull request, please, be sure that your changes are rebased to `dev` branch.

## License

[MIT](LICENSE)
{'fraction_non_alphanumeric': 0.17034531861872554, 'fraction_numerical': 0.00355998576005696, 'mean_word_length': 2.8273160762942777, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 18, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6010587', 'n_tokens_mistral': 3301, 'n_tokens_neox': 3187, 'n_words': 780}