leinaD_natipaC
leinaD_natipaC

Reputation: 4437

How can I change only one of a session object's properties?

To set a session variable I must use Session.set('foo', 'sampletext'). But what if foo is an object foo: {bar: 'sample', xyz: 'text'} and I just want to change foo.bar?

Upvotes: 0

Views: 50

Answers (1)

David Weldon
David Weldon

Reputation: 64312

Session doesn't support this. You'd need to replace the whole object:

var foo = Session.get('foo');
foo.bar = 'something';
Session.set('foo', foo);

However, Session is just an instance of a ReactiveDict, which does support this:

var fooDict = new ReactiveDict('foo');
fooDict.set('bar', 'something');

As long as you name the ReactiveDict, it will survive a hot code push and give you the same benefits of Session.

Upvotes: 2

Related Questions