admin管理员组文章数量:1388039
I understand that the difference between using ReactiveVar and Session variables is, at the basic level, a matter of local vs global variables. ReactiveDict is like a local Session object.
But why use ReactiveDict at all if you're already using ReactiveVar? ReactiveDict doesn't seem to have any advantages over ReactiveVar
I understand that the difference between using ReactiveVar and Session variables is, at the basic level, a matter of local vs global variables. ReactiveDict is like a local Session object.
But why use ReactiveDict at all if you're already using ReactiveVar? ReactiveDict doesn't seem to have any advantages over ReactiveVar
Share Improve this question asked Nov 3, 2015 at 23:20 Merlin -they-them-Merlin -they-them- 2,9604 gold badges25 silver badges39 bronze badges2 Answers
Reset to default 9Here are the main differences between ReactiveDict
(RD) and ReactiveVar
(RV):
- As its name implies, RD offers dictionary-like semantics:
set
takes a key/value pair and it hasdelete
andclear
methods. The bottom line is it lets you cluster reactive data into a single variable. Frankly, this isn't all that interesting in most use cases, but keep reading. - RD has an
all
method which returns all of the key/value pairs and registers a reactive dependency on each of them. The main benefit is that if you have a cluster of related reactive data you can fire anautorun
whenever any part of the dictionary changes. To do this with a set of RVs, you'd need to callget
on each of them. - If you pass a name into the RD constructor, it will survive a hot code push. In fact, Session is actually just an RD.
In practice, I've found a few use cases for RDs, but RVs are what you'll likely choose in most situations.
Remended reading: the ReactiveDict
source code
"... a general-purpose reactive datatype for use with tracker."
"If you provide a name to its constructor, its contents will be saved across Hot Code Push client code updates."
source: https://atmospherejs./meteor/reactive-dict
本文标签: javascriptMeteor ReactiveVar vs ReactiveDictStack Overflow
版权声明:本文标题:javascript - Meteor: ReactiveVar vs ReactiveDict - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744529050a2610918.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论