Skip to content
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

fix:remove extra data in actionInfoIndex #84

Merged
merged 1 commit into from
Jun 25, 2023
Merged

Conversation

zttonly
Copy link
Contributor

@zttonly zttonly commented Jun 25, 2023

修复以下问题:
当store内同步action包含异步action,且异步action未使用return语句返回时,若异步action执行时间较长,此时同步action为done的状态从 actionInfos内删除,但是actionInfoIndex 未能删除,会出现根据id取出的actionInfo和实际不对应,可能导致循环。

复现代码:

store.addAction('changeUserName', (name, {dispatch}) => {
    dispatch('chanegX', 1);
    dispatch('changeY', 2);
});
store.addAction('chanegX', (name, {dispatch}) => {
    console.log('changeX');
    setTimeout(() => {
        console.log('setTimeout');
        dispatch('chanegZ');
    }, 1000);
});
store.addAction('changeY', (name, {dispatch}) => {
    console.log('changeY');
    return builder().set('setCount', name);
});
store.addAction('chanegZ', (name, {dispatch}) => {
    console.log('chanegZ');
    dispatch('chanegZCB');
});
store.addAction('chanegZCB', (name, {dispatch}) => {
    console.log('chanegZCB');
});
e1dd6d25417bc6a9b44baab4a65151da 2d5c9a721a534afa7c0326460759c25c

图中可见由于 actionInfoIndex内的数据残余,取出的id为7的actionInfo存在问题,在处理_detectActionDone(actionInfo.parentId) 时陷入死循环,最终导致栈溢出

@errorrik errorrik merged commit 0c2fdf1 into baidu:master Jun 25, 2023
errorrik added a commit that referenced this pull request Jun 25, 2023
errorrik added a commit that referenced this pull request Jun 25, 2023
zttonly added a commit to zttonly/san-store that referenced this pull request Jun 26, 2023
errorrik added a commit that referenced this pull request Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants