microsoft / redux-dynamic-modules

Modularize Redux by dynamically loading reducers and middlewares.
https://redux-dynamic-modules.js.org
MIT License
1.07k stars 116 forks source link

How to wait completion of initialactions when I use a module dependencies? #120

Open sinack-old opened 4 years ago

sinack-old commented 4 years ago

I have 2 modules. There are authModule and userPageModule.

authModule is get user login status by initialactions. userPageModule is used to display the user page using the fetched login status by authModule.

Therefore, I want these modules to be loaded in the correct order. But looks like userPageModule will be loaded without waiting for initialaction of authModule to complete to me.

Is the order of this process correct? If so, how can I do what I want?

export const authModule = () => {
  return {
    id: 'auth',
    reducerMap: {
      auth: authReducer,
    },
    sagas: [watchAuthUser],
    initialActions: [getLoginStatus.start()],
  };
};
export const userPageModule = () => {
  return {
    id: 'userPage',
    reducerMap: {
      profile: profileReducer,
    },
    sagas: [watchPage],
  };
};
export const UserPage = () => (
  <DynamicModuleLoader modules={[authModule(), userPageModule() ]}>
    <Page />
  </DynamicModuleLoader>
);

const Page = () => (
  <>
    // some components that use user data
  </>
)