ReactiveDict is probably not what you want in this case. What you probably want is a single ReactiveVar which holds an object which can be altered. The ReactiveVar then triggers re-run at that level. That of course is complicated and expensive.
You could also extend the existing ReactiveDict object by modifying it’s structure a bit. By default it has a series of observers based on the key, but you’d want to add an observer based on the whole object and a get that triggers that.
A (very rough) example of how one might start to go about this:
var oldSet = ReactiveDict.set;
_.extend(ReactiveDict.prototype, {
set: function (keyOrObject, value) {
var ret = oldSet.call(this, keyOrObject, value);
var self = this;
if (self.keyDeps['_allValues']) {
self.keyDeps['_allValues'].changed();
}
return ret;
},
getAll: function () {
var self = this;
self._ensureKey('_allValues');
self.keyDeps['_allValues'].depend();
return self.keys;
}
});
getAll will return an object with each value being an EJSON string. It will also set up a dependency on the entire dictionary.
I’ll leave it as an exercise for you to improve this if you want to use it. Recommendations for improvement:
Iterate over self.keys and EJSON parse each one.
Find out if anything will actually change when set is called and only trigger the dependency changed method if it actually did.
Template.profile.helpers({
getProfileComment: function () {
let tmp = Template.instance().userProfile.get(); << keep helper reactive by get() call
return tmp.comment; << return one of the profile fields value,
} });