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

有考虑针对这样的场景进行优化吗 #6

Closed
huzw1995 opened this issue Mar 22, 2022 · 4 comments
Closed

有考虑针对这样的场景进行优化吗 #6

huzw1995 opened this issue Mar 22, 2022 · 4 comments

Comments

@huzw1995
Copy link

Demo在这里:https://codesandbox.io/s/resso-forked-1mbs58?file=/src/App.jsx
我觉得这样的场景是可能存在的,当使用resso时对象操作的层级比较深时,又想同时进行相应的视图更新的时候会比较麻烦

@nanxiaobei
Copy link
Owner

nanxiaobei commented Mar 22, 2022

要实现得深层遍历 proxy,目前不考虑这样的方式。

https://zhuanlan.zhihu.com/p/468417292 "6. resso 的使用方式" 中有解释

本文中情形可以这么写,保证最后有一次重新赋值就行:

store.count.a.b.c += 1;
store.count = { ...store.count };

@huzw1995
Copy link
Author

嗯,但是我这个demo,proxy就算只监听一层应该还是能监听到数据变化的,我看了你的源码,这个demo没有触发重渲染应该是在后续的useState的setValue上面。我是挺喜欢你这样的极简设计的,代码量也很少,值得学习,但是用起来感觉还是有限制的,有空我fork下自己研究一下吧

@nanxiaobei
Copy link
Owner

监听一层不会的,无论是 MobX 还是 valtio,都需要深层递归去监听。

@huzw1995
Copy link
Author

image
我刚又琢磨了一下,好像的确是不会进到这个if里面,是需要深层监听的。

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

No branches or pull requests

2 participants