All Projects → jamesb3ll → reduxbag

jamesb3ll / reduxbag

Licence: other
👜Callbag RxJS-like middleware for asynchronous side effects in Redux

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to reduxbag

callbag-subscribe
A callbag sink (listener) that connects an Observer a-la RxJS. 👜
Stars: ✭ 17 (-64.58%)
Mutual labels:  callbag
react-callbag-listener
👂 A React render-prop component that listens to values emitted by callbags
Stars: ✭ 21 (-56.25%)
Mutual labels:  callbag
awesome-callbags
Callbag Libraries & Learning Material https://github.com/callbag/callbag
Stars: ✭ 85 (+77.08%)
Mutual labels:  callbag
use-callbag
👜 Use callbag as React hook.
Stars: ✭ 34 (-29.17%)
Mutual labels:  callbag
Callbag Basics
👜 Tiny and fast reactive/iterable programming library
Stars: ✭ 1,619 (+3272.92%)
Mutual labels:  callbag
callbag-rs
Rust implementation of the callbag spec for reactive/iterable programming
Stars: ✭ 25 (-47.92%)
Mutual labels:  callbag
go-callbag
golang implementation of Callbag
Stars: ✭ 19 (-60.42%)
Mutual labels:  callbag

reduxbag

Callbag-based middleware for Redux.

  • Tiny (<350b)
  • Zero dependencies
  • Similar API to redux-observable
  • “Unlimited” operators (callbag ecosystem)

Install

yarn add reduxbag
# -- or --
npm install --save reduxbag

Usage

import map from 'callbag-map';
import pipe from 'callbag-pipe';
import mapPromise from 'callbag-map-promise';
import { createStore, applyMiddleware } from 'redux';
import createReduxbagMiddleware, { ofType } from 'reduxbag';

const todos = (state = [], action) => {
  switch (action.type) {
    case 'ADD_TODO':
      return state.concat(action.text);
    default:
      return state;
  }
}

const ajaxEpic = (action$, store) => pipe(
  action$,
  ofType('FETCH_TODO'),
  mapPromise(action =>
    fetch(`//jsonplaceholder.typicode.com/posts/${(1+Math.random()*50)>>0}`)
    .then(res => res.json())
  ),
  map(data => ({
    type: 'ADD_TODO',
    text: data.title,
  })),
);

const store = createStore(
  todos,
  applyMiddleware(createReduxbagMiddleware(ajaxEpic)),
);

const logState = () => console.log(store.getState());
store.subscribe(logState);
logState();

store.dispatch({ type: 'ADD_TODO', text: 'Try out callbags' });
store.dispatch({ type: 'FETCH_TODO' });
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].