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

subscriptions的适用场景? #3

Closed
codering opened this issue Jun 29, 2016 · 1 comment
Closed

subscriptions的适用场景? #3

codering opened this issue Jun 29, 2016 · 1 comment

Comments

@codering
Copy link
Contributor

codering commented Jun 29, 2016

subscriptions会在domReady后全部都执行,而且没有任何约束。
对于需登录的系统,subscriptions是不应该执行的;
或者重刷当前页面,其他页面的subscriptions 也不应该执行;
该怎么控制比较好些?在每个subscriptions里面自己再做一次判断?

@sorrycc
Copy link
Member

sorrycc commented Jun 29, 2016

需登录的系统,通常需要做什么初始化的操作?


Subscription 语义是订阅,用于订阅一个数据源,然后根据条件 dispatch action。数据源可以是当前的时间、服务器的 websocket 连接、keyboard 输入等。

举几个我觉得适用的场景:

  1. 监听 history 改变,如果满足需求,触发 action,详见:friend list
  2. 和服务器建立 SSEWebsockets 连接,收到消息后,触发 action
  3. 监听 keyboard 输入,实现快捷键功能
  4. 监听 geolocation 改变
  5. 初始化服务器数据查询,详见:popular products
  6. ...

更多关于 subscription,见:http://elm-lang.org/blog/farewell-to-frp

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