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

怎样结束一个stream? #21

Open
songdun opened this issue Jan 16, 2017 · 6 comments
Open

怎样结束一个stream? #21

songdun opened this issue Jan 16, 2017 · 6 comments

Comments

@songdun
Copy link

songdun commented Jan 16, 2017

问题背景:
有一个modal框,内容为react-most组件content,modal show的时候加载content,modal hide的时候解绑content,modal本身不会解绑只是display: none,而content都是重新加载,content加载的时候会发送一条请求获取数据。
出现问题:
如果页面不刷新,每次关闭modal再打开时,content发送的请求数都会比上一次多1次,如:第一次打开时获取数据的请求发送1次,不刷新页面关闭modal再打开,获取数据请求发送2次,再关闭再打开,获取数据请求发送3次,以此类推。


我觉得可能是因为每次加载content的时候都是重新加载,因此就会创建一条stream,而关闭modal的时候只是解绑modal里的content而stream还存在,所以再加载一个新的content的时候就有两条stream存在了,所以发送了2次请求,不知道欧阳老师有什么看法?请指教

@jcouyang
Copy link
Collaborator

content内容是 <Most/> 还是 <Connect />
正常如果是 Connect,会在componentUnmount的时候解绑stream
如果是 Most,不应该 mount和umount Most,Most一般是作为根
另外可能一种情况是,数据请求是副作用,如果并没有返回成 sink,这种情况react-most也没有办法帮你unsubscribe

@songdun
Copy link
Author

songdun commented Jan 16, 2017

content是Connect,有没有什么方法能检测是否已经解绑stream? 或是检测数据请求是不是返回成了sink?

@jcouyang
Copy link
Collaborator

只需要把connect的函数写纯就好了,比如你connect上去的函数有没有自己创建一个stream自己消费,没有return出去的这种情况

@songdun
Copy link
Author

songdun commented Jan 16, 2017

您说的情况应该不会发生 我只是按照您的例子写的model并没有单独创建一个stream,我测试了没有放在modal的页面,每次都只是发生一次请求,就是这个放在modal里的 会越来越多,这个没有什么调试工具吗?

@jcouyang
Copy link
Collaborator

可以试试

  • env NODE_ENV=debug <你的开始脚本>,在console里面能打出所有intent和state的history
  • react浏览器插件看看到底render了几个component
  • 再不济就debugger断点调试

另外你用的哪个版本的react-most,最好升到最新,因为有一个版本用的most是有unsubscribe的bug的

@songdun
Copy link
Author

songdun commented Jan 16, 2017

好的 我试试看 谢谢

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