All Projects → zmitry → okdux

zmitry / okdux

Licence: MIT License
redux made ok 👌

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HCL
1544 projects

Projects that are alternatives of or similar to okdux

Surmon.me.native
📱 My blog app, powered by react-native
Stars: ✭ 579 (+3518.75%)
Mutual labels:  mobx, react-redux
react-pits
React 中的坑
Stars: ✭ 29 (+81.25%)
Mutual labels:  mobx, react-redux
Apple Basket Redux
🍎 苹果篮子,一个微型的redux/mobx演示(附多版本)
Stars: ✭ 125 (+681.25%)
Mutual labels:  mobx, react-redux
Starcabinet
🎉 开源的跨平台Github Stars管理分析工具
Stars: ✭ 399 (+2393.75%)
Mutual labels:  mobx, react-redux
Alldemo
🍑 2020全栈学习Demo大合集 包含最新 hooks TS 等 还有umi+dva,数据可视化等实战项目 (持续更新中)
Stars: ✭ 189 (+1081.25%)
Mutual labels:  mobx, react-redux
cerebro-web
Website for Cerebro
Stars: ✭ 21 (+31.25%)
Mutual labels:  react-redux
react-native-shopping-app
A shopping app using React Navigation, Redux, Redux-Thunk and Firebase.
Stars: ✭ 67 (+318.75%)
Mutual labels:  react-redux
myConsole
基于 TS + React + Mobx 实现的移动端浏览器控制台开发教程
Stars: ✭ 26 (+62.5%)
Mutual labels:  mobx
react-typescript
A Front-End Project with Typescript/Antd. webpack5+react-router4+antd+typescript4+grahql
Stars: ✭ 63 (+293.75%)
Mutual labels:  mobx
tinylog-ui
实时日志分析系统后台数据管理系统
Stars: ✭ 45 (+181.25%)
Mutual labels:  mobx
react-mobx-router4-axios
react + less + webapck config + mobx(store)+ axios + router4
Stars: ✭ 24 (+50%)
Mutual labels:  mobx
react-redux-exercise
Exercise to understand better react-redux, how it works and how to use it.
Stars: ✭ 48 (+200%)
Mutual labels:  react-redux
fay-react-redux-example
No description or website provided.
Stars: ✭ 14 (-12.5%)
Mutual labels:  react-redux
react-mobx-router5
React components for routing solution using router5 and mobx
Stars: ✭ 58 (+262.5%)
Mutual labels:  mobx
redux-saga-rn-alert
Alert.alert()-Support for side effects with redux-saga in react-native-apps
Stars: ✭ 23 (+43.75%)
Mutual labels:  react-redux
mobx
Код учебного курса “MobX & React” на YouTube-канале webDev (https://tinyurl.com/vt3tk6vy)
Stars: ✭ 23 (+43.75%)
Mutual labels:  mobx
react-native-firebase-starter
The ultimate React Native starter using Firebase, Mobx, CodePush, OneSignal made with ♥
Stars: ✭ 290 (+1712.5%)
Mutual labels:  mobx
react-with-mobx-template
project template-react&&mobx
Stars: ✭ 15 (-6.25%)
Mutual labels:  mobx
network-pipeline
Network traffic data pipeline for real-time predictions and building datasets for deep neural networks
Stars: ✭ 36 (+125%)
Mutual labels:  react-redux
mobx-react-matchmedia
A React HOC with mediaqueries for responsive layout
Stars: ✭ 32 (+100%)
Mutual labels:  mobx

Okdux 👌

CircleCI NPM Downloads

This lib was created for reducing pain from redux boilerplate.


Installation

npm install --save okdux

or

yarn add okdux

Usage

import { createStore } from "redux";
import { connect } from "react-redux";


import { createActions, createState, build } from "okdux";


const actions = createActions({
  inc: build.action<string>()
});

const counterState = createState(0);
// different types of counters
const state = createState({ counter: countersState });

counterState.on(actions.inc, (state, p) => {
  return state + 1;
});

//[optional]auto bind all actions to redux
//store is redux store
state.createStore((reducer)=> createStore(reducer, {}));
// or
const store = createStore(state.reducer, {});
state.use(store.dispatch);

countersState.select(store.getState()); // will return state from root
countersState.select(store.getState()); // will return state from root

// select only counter from root state
// this component will be reuseable and you won't care about where your reducer are placed
// also you will get types suggestions
const enhancer = connect(countersState.select(counter=>({ counter })))


// dispatch actions
// all actions are autobinded to store after using .use action
// you can assign one action to multiple stores
// to access plain action call inc.raw();
// actions are autobinded in case of
inc(1);
inc(2);
inc(2);
inc(3);
inc(8);

API

createState({ //plain obj or different state }) => StateBuilder

create state from plain object or compose from different state

const counter = createState(0);

const state = createState({ counter });

ALERT: YOU CAN PASS to createState either plain obj or map of states

this is ok

const counter = createState(0);
const counter2 = createState(0);

const state = createState({ counter, counter2 });

this is not ok

const counter = createState(0);
const counter2 = createState(0);

const state = createState({ counter, counter2, name: "6" /* not ok*/ });
const state = createState({ counter, counter2, name: createState("name") }); // this is ok

StateBuilder

StateBuilder.on(Action:Action, handler:(substate: any, ActionPayload)=>new substate)

Add handler to substate It's like building reducer but with using .on instead of switch cases in handler as second argument you will get action payload and you have to return new state

StateBuilder.select(RootStateObject)=> state

selects state related to your state builder

StateBuilder.select((subState)=>mappedState)=> mappedState

state with map is equivalent to mapFn(StateBuilder.select({}));

it will return substate related to some stateBuilder Example:

// somewhere in state file;
const counterState = createState(0);

//somewhere in component
// now you can select your counter state and don't care about counter placement in store
const enhancer = connect(countersState.select(counter => ({ counter })));

ALERT: you can have only one stateBuilder mounded to root state

const st = createState(2);
const rootSTate = createState({
  st,
  st2: st
}); // not ok
const makeSt = () => createState(2);
const rootSTate = createState({
  st: makeSt(),
  st2: makeSt()
}); // ok

StateBuilder.reducer: PlainReducer

reducer property it's encapsulated reducer inside state builder

StateBuilder.use(dispatchFn): void

makes all actions binded using on handler autobinded to this function so you won't have to use mapDispatchToProps

StateBuilder.createState(createStoreFn): store

same as use

example

const state = createState(0);
state.createStore(reducer => createStore(reducer, {}));
// or simpler
state.createStore(createStore);

StateBuilder.reset(action): StateBuilder

reset reducer value to default same as state.on(action, ()=>initialValue)

createActions({ [string]: ActionFactory })

examples

import { build, createState, createApi } from "okdux";
const counter = createState(0);

const actions = createApi(counter, {
  increment(state, payload) {
    return { ...state, payload };
  },
  decrement(state, payload) {
    return { ...state, payload };
  }
});
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].