Closed xhubert closed 7 years ago
@idpocky 目前的实现上
onEffect: function (effect, { put }, model, actionType) {
const temp = [];
return function* (...args) {
if (filter(args[0])) {
block.lock(key);
}
yield effect(...args);
if (filter(args[0])) {
block.release(key);
}
}
}
项目中需要有 effect
, 配置中必须添加 asyncActions: ['topic/fetchTopic', ...]
, 名字取的有问题,列表中为 effect
的名字。
刚才加了个effect
测试了一下,还是老样子。
export default ssr.runtimeSSRMiddle({
routes,
createApp,
initialState: {}, // custom initialState
asyncActions: ['topic/fetchTopics'], // async actions in dva
renderFullPage,
onRenderSuccess,
});
我通过修改block.check()
中针对count
的判断后,可以正常显示页面。但是发现asyncActions
中的action
没有被执行啊。
是否dva
的model
定义需要有什么特殊的写法?
@idpocky
effects: {
fetchTopic: [function* ({ payload: { refresh, init, lastTopic } }, { put, call, select }) {
try {
const topic = yield call(
fetchTopics,
);
yield put({ type: 'saveTopic', payload: { topic } });
} catch (e) {
yield put({ type: 'fetchTopicFailed', payload: { error: e } });
}
}, { type: 'takeLatest' }]
}
现在可以了,原来对应的effect
同样是需要subscribe
的。
@idpocky OK
感谢!
另外,对于dva-ssr
这种方式,打包发布,有什么好的实践方案可以分享一下么?
@idpocky
目前的项目的项目经验:
前端与服务器端在同一个项目中,都使用 typescript
进行编写,使用 webpack
进行打包。服务器端可以复用前端代码。
方便分享一个脚手架代码来学习学习么?
@idpocky Sorry,目前只用在公司的项目上,暂时不方便分享。
ok,多谢。
@idpocky 发布了新版本 0.2.0
,支持同步渲染,不用配置 asyncActions
,并且项目不一定要存在
effect
。
@alexayan ok!
场景
IndexPage
的dva
项目进行服务端渲染改造,服务启动后,浏览器访问一直处于加载中。model
中无effect
,空项目。pull
了源码引用后,发现了一个问题:这段代码,在执行的时候,
count
始终为undefined
,所以导致callback()
无法执行到。