- Notifications
You must be signed in to change notification settings - Fork16
janryWang/redux-callbag
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Redux middleware for action side effects withcallbag
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
npm install --save redux-callbag
import{createStore,applyMiddleware}from"redux"import{pipe,filter,forEach,map}from"callbag-basics"importcreateCallbagMiddlewarefrom"./index"importdelayfrom'callbag-delay'consttodos=(state=[],action)=>{switch(action.type){case"ADD_TODO":returnstate.concat([action.payload])case"REMOVE_TODO":return[]case"ADD_SOMETHING":returnstate.concat([action.payload])default:returnstate}}constaddTodo=(payload)=>{return{type:"ADD_TODO", payload}}constaddSomething=(payload)=>{return{type:"ADD_SOMETHING", payload}}constremoveTodo=()=>{return{type:"REMOVE_TODO"}}conststore=createStore(todos,["Hello world"],applyMiddleware(createCallbagMiddleware((actions,store)=>{const{ select, mapPromise, mapSuccessTo, mapFailTo}=actionsactions|>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())})
This API is used to create middleware
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
This API is used to insert promise flow
This API is used to dispatch action when callbags chain is successed
This API is used to dispatch action when callbags chain is failed
You can install the latest version of babel7(@babel/cli), and use @babel/plugin-proposal-pipeline-operator.
The MIT License (MIT)
Copyright (c) 2018 JanryWang
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, 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 THESOFTWARE.
About
🕺🕺Redux middleware for action side effects with callbag 👉< 1KB
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.
