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() {
6262 };
6363}
6464
65- // Could also look into state in the callback form
65+ // Could also read state of a store in the callback form
6666export function incrementIfOdd () {
67- return (dispatch , state ) => {
68- if (state . counterStore % 2 === 0 ) {
67+ return (dispatch , read ) => {
68+ if (read ( counterStore) % 2 === 0 ) {
6969 return ;
7070 }
7171
Original file line number Diff line number Diff line change 22 INCREMENT_COUNTER ,
33 DECREMENT_COUNTER
44} from '../constants/ActionTypes' ;
5+ import { counterStore } from '../stores' ;
56
67export function increment ( ) {
78 return {
@@ -10,8 +11,8 @@ export function increment() {
1011}
1112
1213export function incrementIfOdd ( ) {
13- return ( dispatch , state ) => {
14- if ( state . counterStore . counter % 2 === 0 ) {
14+ return ( dispatch , read ) => {
15+ if ( read ( counterStore ) % 2 === 0 ) {
1516 return ;
1617 }
1718
Original file line number Diff line number Diff line change @@ -121,14 +121,19 @@ export default function createDispatcher() {
121121 const action = actionCreator ( ...args ) ;
122122 if ( typeof action === 'function' ) {
123123 // Callback-style action creator
124- action ( dispatch , currentState ) ;
124+ action ( dispatch , read ) ;
125125 } else {
126126 // Simple action creator
127127 dispatch ( action ) ;
128128 }
129129 } ;
130130 }
131131
132+ // Allow to read the state of a store
133+ function read ( store ) {
134+ return currentState [ getStoreKey ( store ) ] ;
135+ }
136+
132137 return {
133138 wrapActionCreator,
134139 observeStores,
You can’t perform that action at this time.
0 commit comments