<commit_before># react-frau-events

[![NPM version][npm-image]][npm-url]
[![Build status][ci-image]][ci-url]
[![Dependency Status][dependencies-image]][dependencies-url]

A React mixin to mix custom event listener/emitter functions on React components.

## Installation

Install from NPM:
```shell
npm install react-frau-events
```

## Usage

Require the mixin provider:
```javascript
var Emitter = require('react-frau-events');
```

The mixin will add an ***emitEventName*** function with your component, and all associated handlers (if defined) will be invoked when the event is emitted:

```javascript
     var Component = React.createClass({
          mixins: [Emitter.ForEvent('customEvent')],
          onCustomEvent: function() {
               ...
          },
          render: function() {
               ...
          }
     });
```

The event is emitted simply by calling ***emitEventName*** on an instance of the component.

```javascript
     var componentInstance = React.render(
          <Component />,
          node
     );
     componentInstance.emitCustomEvent();
```

### Isolated Emitters

By default, the mixin will use a global/shared event emitter, meaning that all component instances using the mixin will share the same emitter, and emitting an event will call the respective handlers on all the components. It is possible to scope the emitter for components when the mixin specified for the component.

For example, the following would provide an emitter for instances of this component, and when the custom event is emitted, only delegates on instances of Component would be called.

```javascript
     var Component = React.createClass({
          mixins: [Emitter.ForEvent('customEvent', new EventEmitter())],
          ...
     });
```

### Promises

A promise is returned from ***emitEventName*** when all of the handlers have completed running. When the promise resolves, the results of the handlers are passed along. This enabled handlers themselves to be asynchronous.

```javascript
     componentInstance.emitValidate(this)
          .then(function(results) {
               ...
          });
```

[npm-url]: https://www.npmjs.org/package/react-frau-events
[npm-image]: https://img.shields.io/npm/v/react-frau-events.svg
[ci-url]: https://travis-ci.org/Brightspace/react-frau-events
[ci-image]: https://img.shields.io/travis-ci/Brightspace/react-frau-events.svg
[dependencies-url]: https://david-dm.org/brightspace/react-frau-events
[dependencies-image]: https://img.shields.io/david/Brightspace/react-frau-events.svg<commit_msg>Update readme.<commit_after># react-frau-events

[![NPM version][npm-image]][npm-url]
[![Build status][ci-image]][ci-url]
[![Dependency Status][dependencies-image]][dependencies-url]

A React mixin to mix custom event listener/emitter functions on React components.

## Installation

Install from NPM:
```shell
npm install react-frau-events
```

## Usage

Require the mixin provider:
```javascript
var Emitter = require('react-frau-events');
```

The mixin will add an ***emitEventName*** function with your component, and all associated handlers (if defined) will be invoked when the event is emitted:

```javascript
     var Component = React.createClass({
          mixins: [Emitter.ForEvent('customEvent')],
          onCustomEvent: function() {
               ...
          },
          render: function() {
               ...
          }
     });
```

The event is emitted simply by calling ***emitEventName*** on an instance of the component.

```javascript
     var componentInstance = React.render(
          <Component />,
          node
     );
     componentInstance.emitCustomEvent();
```

### Isolated Emitters

By default, the mixin will use a global/shared event emitter, meaning that all component instances using the mixin will share the same emitter, and emitting an event will call the respective handlers on all the components. It is possible to scope the emitter for components when the mixin specified for the component.

For example, the following would provide an emitter for instances of this component, and when the custom event is emitted, only delegates on instances of Component would be called.

```javascript
     var Component = React.createClass({
          mixins: [Emitter.ForEvent('customEvent', new EventEmitter())],
          ...
     });
```

### Promises

A promise is returned from ***emitEventName*** when all of the handlers have completed running. When the promise resolves, the results of the handlers are passed along. This enabled handlers themselves to be asynchronous.

```javascript
     componentInstance.emitValidate(this)
          .then(function(results) {
               ...
          });
```

## Contributing

### Code Style

This repository is configured with [EditorConfig](http://editorconfig.org) rules and contributions should make use of them.


[npm-url]: https://www.npmjs.org/package/react-frau-events
[npm-image]: https://img.shields.io/npm/v/react-frau-events.svg
[ci-url]: https://travis-ci.org/Brightspace/react-frau-events
[ci-image]: https://img.shields.io/travis-ci/Brightspace/react-frau-events.svg
[dependencies-url]: https://david-dm.org/brightspace/react-frau-events
[dependencies-image]: https://img.shields.io/david/Brightspace/react-frau-events.svg
{'fraction_non_alphanumeric': 0.1172583081570997, 'fraction_numerical': 0.0, 'mean_word_length': 3.481387478849408, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 12, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1127353', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1416, 'n_words': 481}