Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/albertobasalo/reactor

RxJs store, based on Redux but way more simple.
https://github.com/albertobasalo/reactor

redux rxjs rxjs-store typescript

Last synced: 19 days ago
JSON representation

RxJs store, based on Redux but way more simple.

Awesome Lists containing this project

README

        

> โš  Right now the deployed version at NPM only works with node projects. Browser version is comming soon.

[![npm (scoped)](https://img.shields.io/npm/v/@atomic.builders/reactor)](https://www.npmjs.com/package/@atomic-builders/reactor)

# โ˜ข Reactor

## Reactive-store

Basic _minimalistic REDUX_ made with RxJs

> Production ready **observable state management**

## ๐ŸŽฏ Motivation

โœ… Avoid the use of heavy and complex libraries like _NgRX_

โœ… Less than 100 lines [store.ts](https://github.com/AtomicBuilders/reactor/blob/master/src/store.ts)

## Installation

```bash
npm i @atomic.builders/reactor
```

## โœจ Sample use

```typescript
const initialBasket: Basket = { client: '', items: [], status: '' };
const basket$ = new Store(initialBasket);

// BASIC USAGE
// get snapshot
const currentBasket: Basket = basket$.getState();
console.log(currentBasket);
// observe changes
basket$.getState$().subscribe({
next: basket => console.log({ basket }),
});
// observe selected changes
basket$
.select$(basket => basket.status)
.subscribe({
next: status => console.log({ status }),
});
// setting direct state
basket$.setState({ client: '', items: [], status: 'EMPTY' });

// WHITH ACTIONS
// observe actions
basket$.getActions$().subscribe({
next: action => console.log({ action }),
});
// dispatch simple action
const setClientAction: Action = new Action('SET_CLIENT', {
client: 'John Doe',
status: 'EMPTY',
});
basket$.dispatch(setClientAction);

// WITH A REDUCER
// dispatch action with payload and reducer
const itemPayload: Item = {
name: 'An ACME thing',
units: 19,
unitPrice: 71,
};
const addItemReducer = (basket: Basket, payload: unknown) => {
basket.items = [...basket.items, payload as Item];
basket.status = 'FILLED';
return basket;
};
const addItemAction: Action = new Action('ADD_ITEM', itemPayload, addItemReducer);
basket$.dispatch(addItemAction);
```

## โš™ Workflows

### ๐Ÿ‘จโ€๐Ÿ’ป Dev Workflow

While developing, make sure to install the recommended extensions for a better dev experience.

Run `npm run test:watch` it will run test after each change. Ideal for TDD or testing just in time.

Run `npm run test` it will run all test once and stops. Default for CI/CD most common environments.

If you want also the coverage report then use `npm run test:coverage` .

## ๐Ÿ›  Tools

### ๐Ÿ“ฆ Commits and release

- Use [standard-version](https://www.npmjs.com/package/standard-version) to produce a changelog file from [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)

### ๐Ÿ’… Code style with Prettier

- Installed and configured prettier

> Recommended [prettier extension](https://github.com/prettier/prettier-vscode)

### ๐Ÿ“ Code linting with esLint

- Installed and configured eslint to work with prettier

> Recommended [esLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)

### ๐Ÿงช Code tested with Jest

- Installed and configured **jest** to run specs
- Configured to conform with **eslint**
- Uses `ts-jest` to work natively with **TypeScript**

## ๐Ÿ‘จ Created by Alberto Basalo

> [@albertobasalo](https://twitter.com/albertobasalo)