【发布时间】:2013-03-21 09:15:24
【问题描述】:
我试图通过 Meteor.autorun 更改 Collection (GraphData) 订阅来限制客户端缓存。但我注意到服务器端仅在更改 Session(浏览器 GUI)后才发布数据。对吗?
在客户端,我有以下咖啡脚本代码:
Meteor.startup ->
Meteor.autorun () ->
Meteor.subscribe 'graphdata', Session.get 'graph_name'
在一个函数中,draw_graph,我有
Session.set 'graph_sub', false
Session.set 'graph_name', item_name
ready = Session.get 'graph_sub'
while !(ready)
Meteor.setTimeout (ready = Session.get 'graph_sub'), 1000
Do something with the GraphData subscription
在服务器端我有
Meteor.startup ->
Meteor.publish 'graphdata', (name) ->
if name?
GraphData.find({name: name})
Session.set 'graph_sub', true
我希望在 Session.set 'graph_name', item_name 之后触发服务器端发布,但我注意到我陷入了 while 循环。
我的理解正确吗?无论如何要强制 Session 变量更改在没有 Session 更改的情况下在服务器端引起注意?
【问题讨论】:
-
循环
ready = false; setTimeout((-> ready = true), 1000) until ready不会像你想要的那样工作,它会导致内部(-> ready = true)被称为无数次。 (编辑:将其写成单行以适应这种单行注释格式;编译为 JS 以更清楚地查看问题。) -
它显然不会在您提供的单行中工作,因为 ready 永远不会改变。在我的代码中,一旦服务器端将graph_sub设置为true,我就准备好更改为true。我最初的问题是关于服务器端未能将 graph_sub 设置为 true。
-
是的,这可能有点过时,但我确实认为
ready最终应该在一秒钟后改变(如果达到那么远,然后再改变十亿次),直到那时@ 987654327@ 已通过while循环被调用了可怕的次数。
标签: meteor