提交 73bfc856 authored 作者: vipcxj's avatar vipcxj

hack select in model

上级 acfd0ac2
...@@ -51,6 +51,20 @@ const hackSagaEffects = (module, sagaEffects) => { ...@@ -51,6 +51,20 @@ const hackSagaEffects = (module, sagaEffects) => {
const { type } = action; const { type } = action;
return sagaEffects.put.resolve({ ...action, type: `${module}/${type}` }); return sagaEffects.put.resolve({ ...action, type: `${module}/${type}` });
}; };
const select = (selector, ...args) => {
const _selector = (state, ..._args) => {
const keys = Object.keys(state);
const newState = { ...state };
for (const key of keys) {
if (key.startsWith(`${module}/`)) {
newState[key.substring(module.length + 1)] = newState[key];
delete newState[key];
}
}
return selector(newState, ..._args);
};
return sagaEffects.select(_selector, ...args);
};
const take = (type) => { const take = (type) => {
const { take: oTake } = sagaEffects; const { take: oTake } = sagaEffects;
if (typeof type === 'string') { if (typeof type === 'string') {
...@@ -66,7 +80,7 @@ const hackSagaEffects = (module, sagaEffects) => { ...@@ -66,7 +80,7 @@ const hackSagaEffects = (module, sagaEffects) => {
return oTake(type); return oTake(type);
} }
}; };
return { ...sagaEffects, put, take }; return { ...sagaEffects, put, take, select };
}; };
const hackEffect = (module, effect) => function * effectGenerator(action, sagaEffects) { const hackEffect = (module, effect) => function * effectGenerator(action, sagaEffects) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论