# api

# createStore

createStore(
  modules?: Modules,
  lazyModules: LazyStoreModules,
  options?: {
    initStates?: States,
    middlewares?: Middleware[],
    interceptors?: Interceptor[],
  }
) => Store;

# store api

# getModule

store.getModule('moduleName') => InjectStoreModule

# setModule

store.setModule('moduleName', StoreModule) => Store;

# removeModule

store.removeModule('moduleName') => Store;

# setLazyModule

init/set lazy module

store.setLazyModule('moduleName', () => Promise<StoreModule>) => Store;

# removeLazyModule

remove lazy modul

store.removeLazyModule('moduleName') => Store;

# hasModule

store.hasModule('moduleName') => boolean;

# loadModule

load lazy module If the module is already loaded, return the already loaded module

store.loadModule('moduleName') => Promise<InjectStoreModule>;

# getOriginModule

store.getOriginModule('moduleName') => StoreModule;

# getLazyModule

getLazyModule import function

store.getLazyModule('moduleName') => () => Promise<StoreModule>;

# subscribe

listen module change

export type ModuleEvent = {
  type: 'init' | 'update' | 'remove',
  actionName?: string,
};

export interface Listener {
  (me: ModuleEvent): any;
}

store.subscribe('moduleName', listener: Listener) => Function;

# getAllModuleName

store.getAllModuleName('moduleName') => string[];

# dispatch

run action

store.dispatch(moduleName, actionName, ...actionArg: any[]) => ReturnType<Action>;

# destroy store

store.destroy() => void;

# globalSetStates

// Manually set all state, incoming module name, and corresponding state, it will be updated, and push notification
store.globalSetStates({
  [mn: moduleName]: State;
})

# globalResetStates

// Use store to initialize the state of all modules and push notifications
// You can pass, exclude, include to filter modules that do not need to be initialized, exclude is higher than include
store.globalResetStates({
  exclude: Arrary<string|RegExp>;
  include: Arrary<string|RegExp>,
})

# get all states

store.getAllStates();

# inject api

# createInject

createInject({
  storeGetter: () => Store,
  loadingComponent: React.ComponentClass<{}> | React.FC<{}>
})

# inject


type ModuleDepDec = [string, {
  state?: Array<string|Function>;
  maps?: Array<string>;
}]
type TReactComponent<P> = React.FC<P> | React.ComponentClass<P>;

type StoreProps = {[m: string]: InjectStoreModule}

inject<T extends StoreProps>(...moduleDec: Array<string|ModuleDepDec>) 
=> <P extends T>(
  WrappedComponent: TReactComponent<P>, 
  LoadingComponent?: TReactComponent<{}>
) => React.ComponentClass<Omit<P, keyof T> & { forwardedRef?: React.Ref<any> }>

Last Updated: 5/1/2021, 1:47:35 PM