Redux-Thunk-dispatch multi actions one by one2017-10-15 14:48

Redux 里面 dispatch 多个 action, 其实很简单:

先 dispatch 一个 非延时操作, 然后 return 一个 thunk

export const setting_toggleAutoSave = autoSave => (dispatch, getState) => {
  dispatch({
    type: 'SETTING_CHANGE_AUTOSAVE',
    autoSave,
  });
  return dispatch(setting_write());
};

export const setting_write = () => (dispatch, getState) => {
  console.log('setting.write', getState().app.settings);
  FileSystem.writeAsStringAsync(
`${FileSystem.documentDirectory}setting.json` ,
    JSON.stringify(getState().app.settings)
  );
};
Powered by Remix
|
Designed by szhshp
|
Copyright © szhshp 2022