All Projects β†’ janryWang β†’ Redux Callbag

janryWang / Redux Callbag

πŸ•ΊπŸ•ΊRedux middleware for action side effects with callbag πŸ‘‰< 1KB

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Redux Callbag

Mag.js
MagJS - Modular Application Glue
Stars: ✭ 157 (-11.3%)
Mutual labels:  reactive, observable
Ngx Restangular
Restangular for Angular 2 and higher versions
Stars: ✭ 787 (+344.63%)
Mutual labels:  reactive, observable
Mikado
Mikado is the webs fastest template library for building user interfaces.
Stars: ✭ 323 (+82.49%)
Mutual labels:  reactive, observable
rx-ease
Spring animation operator for rxjs 🦚✨
Stars: ✭ 16 (-90.96%)
Mutual labels:  reactive, observable
Redux Most
Most.js based middleware for Redux. Handle async actions with monadic streams & reactive programming.
Stars: ✭ 137 (-22.6%)
Mutual labels:  reactive, observable
react-mobx-router5
React components for routing solution using router5 and mobx
Stars: ✭ 58 (-67.23%)
Mutual labels:  reactive, observable
Formily
Alibaba Group Unified Form Solution -- Support React/ReactNative/Vue2/Vue3
Stars: ✭ 6,554 (+3602.82%)
Mutual labels:  reactive, observable
rxrest
Reactive rest library
Stars: ✭ 33 (-81.36%)
Mutual labels:  reactive, observable
React Eva
Effects+View+Actions(React distributed state management solution with rxjs.)
Stars: ✭ 121 (-31.64%)
Mutual labels:  reactive, observable
Rxviz
Rx Visualizer - Animated playground for Rx Observables
Stars: ✭ 1,471 (+731.07%)
Mutual labels:  reactive, observable
observable ish
Observable state and events for browser and Flutter.
Stars: ✭ 26 (-85.31%)
Mutual labels:  reactive, observable
Kefir
A Reactive Programming library for JavaScript
Stars: ✭ 1,769 (+899.44%)
Mutual labels:  reactive, observable
immerx-state
Reactive, fractal and no-nonsense state management with Immer
Stars: ✭ 19 (-89.27%)
Mutual labels:  reactive, observable
callbag-rs
Rust implementation of the callbag spec for reactive/iterable programming
Stars: ✭ 25 (-85.88%)
Mutual labels:  reactive, observable
realar
5 kB Advanced state manager for React
Stars: ✭ 41 (-76.84%)
Mutual labels:  reactive, observable
Observable
The easiest way to observe values in Swift.
Stars: ✭ 346 (+95.48%)
Mutual labels:  reactive, observable
Rocket.jl
Functional reactive programming extensions library for Julia
Stars: ✭ 69 (-61.02%)
Mutual labels:  reactive, observable
Marble
Marble.js - functional reactive Node.js framework for building server-side applications, based on TypeScript and RxJS.
Stars: ✭ 1,947 (+1000%)
Mutual labels:  reactive, observable
Qactive
Reactive queryable observable framework.
Stars: ✭ 147 (-16.95%)
Mutual labels:  reactive, observable
Vue Chimera
VueJS reactive RESTful API
Stars: ✭ 160 (-9.6%)
Mutual labels:  reactive

npm version Build Status

Redux middleware for action side effects with callbag

You may not need redux-saga/redux-observable. When you use redux-callbag, you will find that this's what you want.

  • πŸ™€ Minisize
  • πŸ™€ Scalable
  • πŸ™€ Easy to understand

Install

npm install --save  redux-callbag

Try it online

Usage

import { createStore, applyMiddleware } from "redux"
import { pipe, filter, forEach, map } from "callbag-basics"
import createCallbagMiddleware from "./index"
import delay from 'callbag-delay'

const  todos = (state = [], action)=> {
    switch (action.type) {
        case "ADD_TODO":
            return state.concat([action.payload])
        case "REMOVE_TODO":
            return []
        case "ADD_SOMETHING":
            return state.concat([action.payload])
        default:
            return state
    }
}

const addTodo = (payload)=> {
    return {
        type: "ADD_TODO",
        payload
    }
}

const addSomething = (payload)=> {
    return {
        type: "ADD_SOMETHING",
        payload
    }
}

const removeTodo = ()=> {
    return {
        type: "REMOVE_TODO"
    }
}



const store = createStore(
    todos,
    ["Hello world"],
    applyMiddleware(
        createCallbagMiddleware((actions, store) => {
            const {
                select,
                mapPromise,
                mapSuccessTo,
                mapFailTo
            } = actions
            
            actions
                |> select("ADD_SOMETHING")
                |> delay(1000)
                |> forEach(({ payload }) => {
                    console.log("log:" + payload)
                })

            actions
                |> select("ADD_TODO")
                |> delay(1000)
                |> mapPromise((d)=>fetch('/xxxx',{data:d}).then(res=>res.json()))
                |> mapSuccessTo("ADD_SOMETHING",(payload)=>payload + "  23333333")
        })
    )
)

store.dispatch(addTodo("Hello redux"))
store.dispatch(addSomething("This will not add numbers"))

console.log(store.getState())

store.subscribe(()=>{
    console.log(store.getState())
})


API

createCallbagMiddleware([...epics : Array<(actions : Function,store : Object) {} :any>]) : Function

This API is used to create middleware

actions.select([...actionType : String]) : Function

This API is used to select action

If action-type is undefined, it is equivalent to select to initialize the action, as you can pass multiple action-types

actions.mapPromise(mapFn : Function<(payload : any) {} : any>) : Function

This API is used to insert promise flow

actions.mapSuccessTo(actionType : String , [mapFn : Function<(payload : any) {} : any])

This API is used to dispatch action when callbags chain is successed

actions.mapFailTo(actionType : String , [mapFn : Function<(payload : any) {} : any])

This API is used to dispatch action when callbags chain is failed

Q/A

How to use pipline operator syntax?

You can install the latest version of babel7(@babel/cli), and use @babel/plugin-proposal-pipeline-operator.

LICENSE

The MIT License (MIT)

Copyright (c) 2018 JanryWang

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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].