with-rematch
🕶 A HoC that implement reducer a la Rematch
Inpired By Rematch.js ♡
Instalation
npm install -g with-rematch
or
yarn add with-rematch
Getting Started
Step 1: Model
const model = state: 0 reducers: { console; // the state console; // the payload passed via action console; // component props return state + payload || 1; } { return state - payload || 1; } async { await ; actions; } lifecycle: { console; } ;
Understanding models is as simple as answering a few questions:
- What is my initial state? state
- How do I change the state? reducers
- How do I handle async actions? effects with async/await
Step 2: HoC Props (state, actions)
Actions is how we trigger reducers & effects in your models. actions
props standardizes your actions without the need for writing action types or action creators.
// reducersactions;actions;actions; // effectsactions;
const Counter = <div> Value: state <button onClick=actionsincrement>INCREMENT</Button> <button onClick=actionsdecrement>DENCREMENT</button> <button onClick=actionsasyncIncrement>ASYNC INCREMENT</button> <button onClick= actions>INCREMENT 5</Button> </View>; modelCounter;
Step 3: Lifecycle
TODO
Complete Example
; const model = state: 0 reducers: { console; // the state console; // the payload passed via action console; // component props return state + payload || 1; } { return state - payload || 1; } async { await ; actions; } lifecycle: { console; } ; const Counter = <div> Value: state <button onClick=actionsincrement>INCREMENT</Button> <button onClick=actionsdecrement>DENCREMENT</button> <button onClick=actionsasyncIncrement>ASYNC INCREMENT</button> <button onClick= actions>INCREMENT 5</Button> </View>; modelCounter;