File tree Expand file tree Collapse file tree 1 file changed +36
-3
lines changed
Expand file tree Collapse file tree 1 file changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -73,10 +73,37 @@ app.update(_initialState => ({count: 1})) // it fires rendering
7373- ` Flux ` is ` EventEmitter `
7474- ` Component ` is just ` ReactComponent ` with ` dispatch ` method.
7575
76- ## Middlewares
76+ ## With decorator
7777
78- Middleware function type is ` <T>(t: T) => T | Promise<T> ` or ` <T>(t: Promise<T>) => Promise<T>; ` . (Use Promise.resolve if you consider promise)
79- ` Flux#render(state) ` is always promise unwrapped promise but a middelware handle raw nextState received by ` Flux#update ` .
78+ Added by v0.3.0. Need babel-plugin-transform-decorators-legacy.
79+
80+ ``` js
81+ import React from ' react'
82+ import {withFlux , dispatchable } from ' ../../src/flumpt'
83+
84+ @dispatchable
85+ class CounterIncrement extends React .Component {
86+ render () {
87+ return < button onClick= {_ev => this .context .dispatch (' increment' )}> + 1 < / button>
88+ }
89+ }
90+
91+ @withFlux ((update , on ) => {
92+ on (' increment' , () => {
93+ update (state => {
94+ return {count: state .count + 1 }
95+ })
96+ })
97+ }, {count: 0 })
98+ class MyApp extends React .Component {
99+ render () {
100+ return < div>
101+ < span> {this .props .count }< / span>
102+ < CounterIncrement/ >
103+ < / div>
104+ }
105+ }
106+ ```
80107
81108## With TypeScript
82109
@@ -107,6 +134,12 @@ class App extends Flux<State> {
107134
108135See detail in ` index.d.ts `
109136
137+ ## Middlewares
138+
139+ Middleware function type is ` <T>(t: T) => T | Promise<T> ` or ` <T>(t: Promise<T>) => Promise<T>; ` . (Use Promise.resolve if you consider promise)
140+ ` Flux#render(state) ` is always promise unwrapped promise but a middelware handle raw nextState received by ` Flux#update ` .
141+
142+
110143## LICENSE
111144
112145MIT
You can’t perform that action at this time.
0 commit comments