stamen icon indicating copy to clipboard operation
stamen copied to clipboard

当多个组件订阅Store时,每个Update后都会计算一次nextState导致状态丢失和性能问题

Open mapoio opened this issue 5 years ago • 2 comments

Hello,作者,我已经在自己项目中使用了这个状态管理,非常好用。但是发现一个可能导致状态出错的地方,在下方代码中 https://github.com/forsigner/stamen/blob/84a52736915a6928beca48e6c60736f6dee2de57/src/index.tsx#L53-L57
https://github.com/forsigner/stamen/blob/84a52736915a6928beca48e6c60736f6dee2de57/src/index.tsx#L31-L38
这导致每次dispatch后,每个订阅组件更新都会触发set重新设置storeState,这里可能会存在一些性能问题和不可预料的BUG,我在生产环境中已经碰到这些问题了,我自己克隆了一份并且设置每次Dispatch值会触发一次storeState Update后再去set更新组件,这里可以直接计算一次next storeState后直接set就ok了

非常抱歉我已经忘记了是什么BUG导致我发现这一问题,看到作者这里有更新后,我先反馈一下此问题。

mapoio avatar May 11 '19 02:05 mapoio

这个Bug能修复吗?近期也打算在项目中采用stamen了。

tianlinzx avatar Aug 25 '19 13:08 tianlinzx

// if (equal(selector(storeState), selector(nextState))) return 貌似 加上这一行就行了吧?

huyansheng3 avatar May 29 '20 03:05 huyansheng3