Reputation: 1866
So, I might be missing something, but everyone says ReactiveDict is better than Session when storing instance values. But, what about hashing? It doesn't seem as though reactiveDict can hide data like storing in the Session? I am able to get the data from the app through the console using reactiveDict... so, if I wanted to hide this instance data, wouldn't it make sense to use Session?
Thoughts?
appState = new ReactiveDict('appState')...;
Session.set(key, value)...
Upvotes: 0
Views: 168
Reputation: 3043
If you can see the source code for session package here https://github.com/meteor/meteor/blob/devel/packages/session/session.js
Session = new ReactiveDict('session');
Session is nothing but a ReactiveDict.
Reason why people say ReactiveDict is better than session is, Session is global, you can go to console and type Session.keys
to get all the values.
Where as ReactiveDict
has option to not make it global
if you want to use ReactiveDict
in single file you can use like below
const appState = new ReactiveDict('appState')
.
.
.
appState.set('key', 'value');
.
.
.
appState.get('key');
here appState
is not global.
If you want to use same across different files, you can use import and export like below
set.js
------
const appState = new ReactiveDict('appState')
appState.set('key', 'value');
.
.
.
export default appState
then
get.js
------
import appState from './set.js';
appState.get('key'); //result will be value'
So the advantage reactivedict has over session is, session is global where as reactivedict can be not global.
Upvotes: 3