Can I subscribe to Meteor Session for reactive template render updates?

前端 未结 4 1587
余生分开走
余生分开走 2021-01-07 11:43

Is there a way to subscribe to the Meteor Session object so that a reactive template view automatically renders when data is .set on the Session object? Specifically the ke

4条回答
  •  梦谈多话
    2021-01-07 12:31

    I don't think so.

    Have a look at https://github.com/meteor/meteor/blob/master/packages/session/session.js. It's actually reasonably simple. The invalidation happens in lines 45-47. You'll see calling Session.set invalidates anyone listening to that key specifically (via Session.get) or to the new or old value (via Session.equals). Nothing in there about invalidating the session as whole.

    On the other hand, considering how simple it is, it wouldn't be super hard to write your own data structure that does what you want. I'm not sure what your use case is, but it might make a lot of sense to separate it from the session.

提交回复
热议问题