Euphe
Euphe

Reputation: 3709

How do I make an object reactive in Meteor?

Let's say I have an object

var object = {
name: "Example",
value: 1
}

I want to put it in a session

Session.set("Display", object);

and have an handlebars template show it on the page.

Then, if I do

object.value += 1

I want the page to instantly display 2 without the need to call Session.set("Display", object); again. Is this possible?

Upvotes: 0

Views: 1839

Answers (1)

Tarang
Tarang

Reputation: 75975

You have to use the Session.set after. If you want to avoid that you have to make your own reactive objects (which will at their core do the same thing that Session.set does).

If you still want to go about it this way there is a package on the atmosphere repository called reactive-extra which can help you make your own reactive objects:

var obj = new ReactiveObject({name: "Example",value: 1});
obj.value +=1;

Upvotes: 2

Related Questions