-
-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在一个module模块里,如何访问其它module模块的数据 #10
Comments
import { getState } from 'concent';
export function someReducerFn(){
const barState = getState('bar');//获得bar模块状态
}
export interface IActionCtxBase {
callerModule: string;
module: PropKey;
committedStateMap: IAnyObj,
committedState: IAnyObj,
invoke: typeof refCtxInvoke;
lazyInvoke: typeof refCtxInvoke;
dispatch: typeof refCtxDispatch;
lazyDispatch: typeof refCtxDispatch;
rootState: IAnyObj;
globalState: IAnyObj;
moduleState: IAnyObj;
moduleComputed: IAnyObj;
setState: (obj: IAnyObj) => Promise<IAnyObj>;
refCtx: IAnyObj;
} 从描述可看出 import { getState } from 'concent';
export function someReducerFn(payload, moduleState, actionCtx){
const barState = actionCtx.rootState.bar;//获得bar模块状态
} bay the way,如果想在foo模块的reducer方法里调用bar模块的reducer方法去改变bar模块的状态有3种方法
// code in models/foo/reducer.js
// 同步调用
export async function someReducerFn(payload, moduleState, actionCtx){
const ret = await actionCtx.dispatch('bar/someMethod', {val:'this is payload'});
}
// 异步调用
export function someReducerFn(payload, moduleState, actionCtx){
actionCtx.dispatch('bar/someMethod', {val:'this is payload'});
}
// code in models/foo/reducer.js
import * as barRd from 'models/bar/reducer';
// 同步调用
export async function someReducerFn(payload, moduleState, actionCtx){
const ret = await actionCtx.dispatch(barRd.someMethod, {val:'this is payload'});
}
// 异步调用
export function someReducerFn(payload, moduleState, actionCtx){
actionCtx.dispatch(barRd.someMethod, {val:'this is payload'});
}
// code in models/foo/reducer.js
import { reducer } from 'concent';
// 同步调用
export async function someReducerFn(payload, moduleState, actionCtx){
const ret = await reducer.bar.someMethod({val:'this is payload');
}
// 异步调用
export function someReducerFn(payload, moduleState, actionCtx){
reducer.bar.someMethod({val:'this is payload');
} 此种方法不推荐,因为会失去追踪源头调用处的能力(从哪个ui实例发起的调用),当然如果用户不在乎复盘源头调用处那么就无所谓了 此方法更适合在开发模式下,打开console,输入 |
已解决 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
如下图所示 foo模块中的reducer如何访问到 bar模块中的 name 变量?
谢谢!
The text was updated successfully, but these errors were encountered: