# react-influx

> ES6 React 0.14 Component, Dispatcher, Store communication

Latest version **1.1.5** (published 2016-04-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-influx
pnpm add react-influx
yarn add react-influx
bun add react-influx
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.5 |
| Published | 2016-04-09 |
| First published | 2015-11-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Mathew Kurian |
| Maintainers | bluejamesbond |

## Links

- npm: https://www.npmjs.com/package/react-influx
- Repository: https://github.com/bluejamesbond/Influx.js
- Homepage: https://github.com/bluejamesbond/Influx.js#readme
- Issues: https://github.com/bluejamesbond/Influx.js/issues
- npm.io page: https://npm.io/package/react-influx

## Dependencies (2)

- [flux](https://npm.io/package/flux.md) ^2.1.0
- [react](https://npm.io/package/react.md) ^0.14.0

## Recent versions

- 1.1.5 (latest) — 2016-04-09
- 1.1.4 — 2016-04-09
- 1.1.3 — 2016-03-14
- 1.1.2 — 2016-03-14
- 1.1.1 — 2016-03-14
- 1.1.0 — 2016-03-14
- 1.0.9 — 2016-03-14
- 1.0.8 — 2016-01-26
- 1.0.7 — 2016-01-20
- 1.0.6 — 2015-11-15
- 1.0.5 — 2015-11-10
- 1.0.4 — 2015-11-10
- 1.0.3 — 2015-11-10
- 1.0.2 — 2015-11-09
- 1.0.1 — 2015-11-09
- … 1 more at https://npm.io/package/react-influx/versions

## README

# Influx.js
ES6 React 0.14 Component, Dispatcher, Store communication

```
npm install react-influx
```

### Dispatcher.js
```jsx
const Events = keyMirror({
  INCREMENT: null,
  ALERT: null
});

class Dispatcher extends Influx.Dispatcher {
  // override as needed
}

export default Dispatcher.construct(Dispatcher, Events)
```

### App.jsx
```jsx
class App extends Influx.Component {
  constructor(...args) {
    super(...args);
    const count = Store.getCount();
    this.state = {count};
  }

  getListeners() {
    return [
      [Dispatcher, Dispatcher.Events.ALERT, '_onAlert'],
      [Store, Store.Events.UPDATED, this._onIncrement]
    ]
  }

  _onAlert(message) {
    alert(message);
  }

  _onIncrement(count) {
    // Store.getCount() === count
    this.setState({count});
  }

  render() {
    return (
      <div>
        <h5>Component ▶ Dispatcher ▶ Store ▶ Component</h5>
        <div>{this.state.count}</div>
        <button onClick={()=>Dispatcher.emit(Dispatcher.Events.INCREMENT)}>Dispatch INCREMENT</button>
        <br />
        <h5>Component ▶ Dispatcher ▶ Component</h5>
        <div>{this.state.message}</div>
        <button onClick={()=>Dispatcher.emit(Dispatcher.Events.ALERT, "Whatsup!")}>Dispatch ALERT</button>
      </div>
    )
  }
}
```

### Store.js
```jsx
const Events = keyMirror({
  UPDATED: null
});

class Store extends Influx.Store {
  constructor(...args) {
    super(Dispatcher/*,  additional dispatchers you have */);
    this.data = {count: 0};
    this.className = this.constructor.name;
  }

  getCount() {
    return this.data.count;
  }

  getDispatcherListeners() {
    return [
      [Dispatcher, Dispatcher.Events.INCREMENT, '_onDispatcherIncrement'],
      [Dispatcher, Dispatcher.Events.ALERT, this._onDispatcherAlert]
    ]
  }

  _onDispatcherIncrement() {
    this.data.count++;
    this.emit(Events.UPDATED, this.data.count);
  }

  _onDispatcherAlert(message) {
    console.log(message);
  }

  onAction(event, arg0) {
    switch (event) {
      case Dispatcher.Events.INCREMENT:
      case Dispatcher.Events.ALERT:
      default:
        console.info(this.className, "onAction", event, arg0);
    }
  }
}

export default Store.construct(Store, Events)
```

---
_Source: https://npm.io/package/react-influx · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
