# rxsc

> RxSC (ReactiveX State Container) uses the phenomenal RxJS library to provide a Redux-like state container, but with the power of RxJS. Thus the amount of boilerplate code required to get up and running is greatly reduced (see [example](#example)).

Latest version **0.6.0** (published 2017-04-23) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2017-04-23 |
| First published | 2016-12-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | CH Lohmander |
| Maintainers | lohmander |

## Links

- npm: https://www.npmjs.com/package/rxsc
- Repository: https://github.com/lohmander/RxSC
- Homepage: https://github.com/lohmander/RxSC#readme
- Issues: https://github.com/lohmander/RxSC/issues
- npm.io page: https://npm.io/package/rxsc

## Dependencies (1)

- [rxjs](https://npm.io/package/rxjs.md) ^5.0.0-rc.4

## Recent versions

- 0.6.0 (latest) — 2017-04-23
- 0.5.0 — 2017-04-17
- 0.4.0 — 2017-01-28
- 0.3.5 — 2017-01-28
- 0.3.4 — 2017-01-28
- 0.3.3 — 2017-01-03
- 0.3.2 — 2017-01-03
- 0.3.1 — 2017-01-01
- 0.3.0 — 2016-12-31
- 0.2.0 — 2016-12-31

## README

# RxSC

RxSC (ReactiveX State Container) uses the phenomenal RxJS library to provide a
Redux-like state container, but with the power of RxJS. Thus the amount of 
boilerplate code required to get up and running is greatly reduced (see [example](#example)).

## Add-ons

- [rxsc-react](https://github.com/lohmander/rxsc-react) For usage with React
- [rxsc-redux-compat](https://github.com/lohmander/rxsc-redux-compat) For dev usage with Redux tools

## Installation

With npm

```sh
$ npm install --save rxsc
```

With yarn

```sh
$ yarn add rxsc
```

## Terms

Since some concepts of Redux has been merged, or does not translate directly
we use some different terms for RxSC.

### Transformer

A transformer takes care of mapping actions to state changes. You define both
the action and its effect on the state in the transformer unlike Redux, where
this is separated into actions, action creators and reducers.

The `Transformer` class constructor takes three arguments
`Transformer(name: string, initialState: any, transforms: Function)`.

- **name** scope name of the transformer, will be the key for the transformer's state
- **initialState** the initialState of the transformer before any action has been performed
- **transforms** a function which takes an action creator and returns a list of transforms

**Example**

```javascript
// transformer.js

import { Transformer } from 'rxsc';

export default new Transformer('counter', 0, action => [
    action('increment').map(amount => state => state + amount),
]);
```

### Container

The `Container` class takes an array of `Transformer`s and merges them into a
single observable. It also provides a nice mapping of all the transformer actions
under the `container.actions$` object.

**Example**

```javascript
// container.js

import { Container } from 'rxsc';
import counterTransformer from './transformer';

const container = new Container([counterTransformer]);

// performing actions
container.actions$.increment(1);
```

## Example

Putting it all together, it might look something like this

```javascript
import { Transformer, Container } from 'rxsc';


const transformer = new Transformer('count', 0, action => [
    action('increment').map(amount => state => state + amount),
    action('decrement').map(amount => state => state - amount),
]);

const container = new Container([transformer]);

container.subscribe(console.log);

container.actions$.increment(1);
container.actions$.increment(2);
container.actions$.decrement(2);
```

Which should give you the following output

```
{ count: 0 }
{ count: 0 }
{ count: 1 }
{ count: 3 }
{ count: 1 }
```

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