# channelizer

> Flux dispatcher/reducer routing abstraction.

Latest version **1.5.1** (published 2016-08-17) · 0 weekly downloads

## Install

```sh
npm install channelizer
pnpm add channelizer
yarn add channelizer
bun add channelizer
```

## 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.5.1 |
| Published | 2016-08-17 |
| First published | 2016-08-07 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | VYNYL |
| Maintainers | wyatt.arent |

## Links

- npm: https://www.npmjs.com/package/channelizer
- Repository: https://github.com/VYNYL/Channelizer
- Homepage: https://github.com/VYNYL/Channelizer#readme
- Issues: https://github.com/VYNYL/Channelizer/issues
- npm.io page: https://npm.io/package/channelizer

## Dependencies (2)

- [flux](https://npm.io/package/flux.md) ^2.1.1
- [lodash](https://npm.io/package/lodash.md) ^4.14.1

## Recent versions

- 1.5.1 (latest) — 2016-08-17
- 1.5.0 — 2016-08-17
- 1.4.6 — 2016-08-17
- 1.4.5 — 2016-08-15
- 1.4.4 — 2016-08-07
- 1.4.3 — 2016-08-07
- 1.4.2 — 2016-08-07
- 1.4.1 — 2016-08-07
- 1.4.0 — 2016-08-07
- 1.3.0 — 2016-08-07
- 1.2.0 — 2016-08-07
- 1.1.2 — 2016-08-07
- 1.1.1 — 2016-08-07
- 1.1.0 — 2016-08-07
- 1.0.1 — 2016-08-07
- … 1 more at https://npm.io/package/channelizer/versions

## README

# Channelizer
Channelizer lets you combine the power of [Flux](http://github.com/facebook/flux) Dispatchers and Reducers within a message queuing interface. Channelizer can be used as both a Store and a Dispatcher.

Take for instance the following (slightly altered) example written by [Facebook](http://github.com/facebook/flux)
```js
// TodoDispatcher.js
import {Dispatcher} from 'flux';

const instance = new Dispatcher();
export default instance;

export const dispatch = instance.dispatch.bind(instance);
```
```js
// TodoStore.js
import Immutable from 'immutable';
import {ReduceStore} from 'flux/utils';
import TodoDispatcher from './TodoDispatcher';

class TodoStore extends ReduceStore {
  getInitialState() {
    return Immutable.OrderedMap();
  }

  reduce (state, action) {
    switch (action.type) {

      case 'todo/complete':
        return state.setIn([action.id, 'complete'], true);

      case 'todo/destroy':
        return state.delete(action.id);

      default:
        return state;
    }
  }
}
const instance = new TodoStore(TodoDispatcher);
export default instance;
```

This can be simplified...
```js
// TodoChannels.js
// Combines the functionality of TodoDispatcher and TodoStore
import Immutable from 'immutable';
import { Channelizer } from 'channelizer';

class TodoChannels extends Channelizer {
  Model() {
    return Immutable.OrderedMap();
  }

  Channels({ receiver }) {

    receiver.world({
      prefix: 'todo/',
      controller: ({ receiver }) => {

      receiver.tune({
        channel: 'complete',
        controller: ({state, incoming}) => state.setIn([incoming.id, 'complete'], true)
      });

      receiver.tune({
        channel: 'destroy',
        controller: ({state, incoming}) => state.delete(incoming.id)
      });

    }});
  }
}
const instance = new TodoChannels();
export default instance;
```

### Dispatch and Store functionality
```js
import TodoChannels from './TodoChannels';
import { Component } from 'react';

class MyComponent extends Component {
	// If you want to use TodoChannel as a store
	// It's just like you expect
	static function getStores() {
		return [TodoChannels]
	}

	function markAsCommplete(id) {
		// Note we're accessing the TodoChannels store dispatcher.
		// We specify the channel as a string and place all data in "outgoing"
		// Outgoing is then sent to the channel controller as "incoming"
		TodoChannels.dispatch({
			channel: 'todo/complete',
			outgoing: { id }
		});
	}
}
```

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