0

我试图通过 Meteor.autorun 更改集合(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 更改的情况下在服务器端引起注意?

4

2 回答 2

0
while !(Session.get 'graph_sub')    
  Meteor.setTimeout (Session.get 'graph_sub'), 1000

Shouldn't the second line be Session.set? Otherwise the session value will never change, and the while loop will never end.

Besides the typo I'm confused why you're using a setTimeout and graph_sub in the first place. Wouldn't this be enough?

if Meteor.isClient
  Meteor.startup ->
    Meteor.autorun ->
      Meteor.subscribe 'graphdata', Session.get 'graph_name'

if Meteor.isServer
  Meteor.startup ->
    Meteor.publish 'graphdata', (name) ->
      GraphData.find name: name
于 2013-03-19T19:54:08.770 回答
0

我认为你应该Do something with the GraphData subscription在回调中Meteor.subscribe

Meteor.startup ->  
  Meteor.autorun () ->
    Meteor.subscribe 'graphdata', Session.get 'graph_name', () ->
      Do something with the GraphData subscription

另请注意,自 0.5.8 起,服务器端不再提供会话:https ://github.com/meteor/meteor/blob/master/History.md#v058 。

于 2013-03-20T10:16:19.110 回答