All Projects → kahlil → flow-state

kahlil / flow-state

Licence: MIT license
UI state management with RxJS.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to flow-state

Store
Aurelia single state store based on RxJS
Stars: ✭ 103 (+212.12%)
Mutual labels:  rxjs, state-management
Model
Angular Model - Simple state management with minimalist API, one way data flow, multiple model support and immutable data exposed as RxJS Observable.
Stars: ✭ 242 (+633.33%)
Mutual labels:  rxjs, state-management
Bloc.js
A predictable state management library that helps implement the BLoC design pattern in JavaScript
Stars: ✭ 111 (+236.36%)
Mutual labels:  rxjs, state-management
Mini Rx Store
Lightweight Redux Store based on RxJS
Stars: ✭ 32 (-3.03%)
Mutual labels:  rxjs, state-management
ngx-mobx
Mobx decorators for Angular Applications
Stars: ✭ 14 (-57.58%)
Mutual labels:  rxjs, state-management
Rxstate
Simple opinionated state management library based on RxJS
Stars: ✭ 46 (+39.39%)
Mutual labels:  rxjs, state-management
Reactive State
Redux-clone build with strict typing and RxJS down to its core. Wrist-friendly, no boilerplate or endless switch statements
Stars: ✭ 135 (+309.09%)
Mutual labels:  rxjs, state-management
Akita
🚀 State Management Tailored-Made for JS Applications
Stars: ✭ 3,338 (+10015.15%)
Mutual labels:  rxjs, state-management
mst-effect
💫 Designed to be used with MobX-State-Tree to create asynchronous actions using RxJS.
Stars: ✭ 19 (-42.42%)
Mutual labels:  rxjs, state-management
ng-effects
Reactivity system for Angular. https://ngfx.io
Stars: ✭ 46 (+39.39%)
Mutual labels:  rxjs, state-management
Platform
Reactive libraries for Angular
Stars: ✭ 7,020 (+21172.73%)
Mutual labels:  rxjs, state-management
space-state
Demo app for Subjecting State to Good Behavior
Stars: ✭ 46 (+39.39%)
Mutual labels:  rxjs, state-management
Focal
Program user interfaces the FRP way.
Stars: ✭ 613 (+1757.58%)
Mutual labels:  rxjs, state-management
Sigi
Well designed effect management framework for complex frontend app
Stars: ✭ 95 (+187.88%)
Mutual labels:  rxjs, state-management
Fluorine
[UNMAINTAINED] Reactive state and side effect management for React using a single stream of actions
Stars: ✭ 287 (+769.7%)
Mutual labels:  rxjs, state-management
Ayanami
🍭 A better way to react with state
Stars: ✭ 129 (+290.91%)
Mutual labels:  rxjs, state-management
ngx-model-hacker-news-example
Example repository with Hacker News implementation using Angular, Angular Material & ngx-model
Stars: ✭ 27 (-18.18%)
Mutual labels:  rxjs, state-management
reactive-store
A store implementation for state management with RxJS
Stars: ✭ 29 (-12.12%)
Mutual labels:  rxjs, state-management
vuse-rx
Vue 3 + rxjs = ❤
Stars: ✭ 52 (+57.58%)
Mutual labels:  rxjs, state-management
redux-interactions
Composing UI as a set of interactions
Stars: ✭ 22 (-33.33%)
Mutual labels:  state-management, reducer

FlowState 🌊

Dead simple Redux and redux-observable library built with RxJS streams. This is an easy way to introduce a stream-based unidirectional dataflow into your app.

Highlights

  • Inspired by Redux and redux-observable
  • The state is delivered with streams
  • Reducers are just functions, no switch-case
  • Isolate side effects that map back to actions

Install

npm install @kahlil/flow-state

Usage

import { createFlowState } from '@kahlil/flow-state';

const flowState = createFlowState();

Dispatch Actions

In your components dispatch actions by passing the action constant and optionally an action payload. The payload can be any value.

flowState.dispatch({ type: 'SOME_ACTION', payload: { some: 'state' } });

Create A State Stream Based On Reducers

In a file that you could call Store, create and expose state streams for your components by passing the respective reducers.

Here is also the place where you can combine state streams if they depend on one another.

// A collection of reducers.
const itemListReducers = {
  deleteItem: (action, state) => state
    .filter(item => state.filter(item.id !== action.payload.id)),
    
  addItem: (action, state) => [...state, action.payload],
  // ...
};

itemListState$ = flowState.createState$(itemListReducers, initialState);

In your component you can now subscribe to the component state stream:

itemListState$.subscribe(state => console.log(state));

Trigger Side Effects

You can trigger your side effects similar to redux-observable by listening to the actions stream, triggering your side effect and return a new action.

Each side effect is a function and has to be passed to flowState.runSideEffects.

The action that the result of each side effect maps to

// An imaginary API.
const serverApi = new serverApi();
const action$ = flowState.getAction$();

const sideEffect1 = action$ => action$
  .filter(action => action.type === 'DELETE_ITEM')
  .switchMap(action => serverApi.deleteItem(action.payload))
  .map(response => ({ type: 'RECEIVE_ITEMS', payload: response }))
  .catch(response => ({ type: 'DELETE_ITEM_ERROR', payload: response.error });

const sideEffect1 = action$ => action$
  .filter(action => action.type === 'ADD_ITEM')
  .switchMap(action => serverApi.addItem(action.payload))
  .map(response => ({ type: 'RECEIVE_ITEMS', payload: response }))
  .catch(response => ({ type: 'ADD_ITEM_ERROR', payload: response.error });

flowState.runSideEffects(sideEffect1, sideEffect2);

License

MIT © Kahlil Lechelt

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].