Skip to content

Commit 7a9ee87

Browse files
committed
feat(middleware): console payload under dev mode
1 parent 2755a04 commit 7a9ee87

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,14 +709,25 @@ export default Model(stores)
709709
import { actionMiddlewares, Model } from 'react-model'
710710
import Example from 'models/example'
711711

712+
// Example, not recommend to use on production directly without consideration
713+
// Write current State to localStorage after action finish
712714
const persistMiddleware: Middleware = async (context, restMiddlewares) => {
713715
localStorage.setItem('__REACT_MODEL__', JSON.stringify(context.Global.State))
714716
await context.next(restMiddlewares)
715717
}
716718

719+
// Use on all models
717720
actionMiddlewares.push(persistMiddleware)
718-
719721
Model({ Example }, JSON.parse(localStorage.getItem('__REACT_MODEL__')))
722+
723+
// Use on single model
724+
const model = {
725+
state: JSON.parse(localStorage.getItem('__REACT_MODEL__'))['you model name']
726+
actions: { ... },
727+
middlewares: [...actionMiddlewares, persistMiddleware]
728+
}
729+
730+
720731
```
721732
722733
[⇧ back to top](#table-of-contents)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-model",
3-
"version": "3.0.0",
3+
"version": "3.0.2",
44
"description": "The State management library for React",
55
"main": "./dist/react-model.js",
66
"umd:main": "./dist/react-model.umd.js",

src/middlewares.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ const consoleDebugger: Middleware = async (context, restMiddlewares) => {
8686
console.log(
8787
'%c Action',
8888
`color: #03A9F4; font-weight: bold`,
89-
context.actionName
89+
context.actionName,
90+
`payload: ${context.params}`
9091
)
9192
await context.next(restMiddlewares)
9293
console.log(

0 commit comments

Comments
 (0)