File tree Expand file tree Collapse file tree 3 files changed +12
-6
lines changed Expand file tree Collapse file tree 3 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -62,10 +62,10 @@ export function incrementAsync() {
62
62
};
63
63
}
64
64
65
- // Could also look into state in the callback form
65
+ // Could also read state of a store in the callback form
66
66
export function incrementIfOdd () {
67
- return (dispatch , state ) => {
68
- if (state . counterStore % 2 === 0 ) {
67
+ return (dispatch , read ) => {
68
+ if (read ( counterStore) % 2 === 0 ) {
69
69
return ;
70
70
}
71
71
Original file line number Diff line number Diff line change 2
2
INCREMENT_COUNTER ,
3
3
DECREMENT_COUNTER
4
4
} from '../constants/ActionTypes' ;
5
+ import { counterStore } from '../stores' ;
5
6
6
7
export function increment ( ) {
7
8
return {
@@ -10,8 +11,8 @@ export function increment() {
10
11
}
11
12
12
13
export function incrementIfOdd ( ) {
13
- return ( dispatch , state ) => {
14
- if ( state . counterStore . counter % 2 === 0 ) {
14
+ return ( dispatch , read ) => {
15
+ if ( read ( counterStore ) % 2 === 0 ) {
15
16
return ;
16
17
}
17
18
Original file line number Diff line number Diff line change @@ -121,14 +121,19 @@ export default function createDispatcher() {
121
121
const action = actionCreator ( ...args ) ;
122
122
if ( typeof action === 'function' ) {
123
123
// Callback-style action creator
124
- action ( dispatch , currentState ) ;
124
+ action ( dispatch , read ) ;
125
125
} else {
126
126
// Simple action creator
127
127
dispatch ( action ) ;
128
128
}
129
129
} ;
130
130
}
131
131
132
+ // Allow to read the state of a store
133
+ function read ( store ) {
134
+ return currentState [ getStoreKey ( store ) ] ;
135
+ }
136
+
132
137
return {
133
138
wrapActionCreator,
134
139
observeStores,
You can’t perform that action at this time.
0 commit comments