What is meteor Session.equals used for?

What does session.equals do in meteor and what is it used for and how is it different from session.set?

+3


source to share


2 answers


Session.equals helps to check if something matches a value. For example.

Session.set("foo", "foo");
Session.equals("foo", "bar"); => false;

Session.set("foo", "bar");
Session.equals("foo", "bar"); => true;

      

It just tells you if the value matches the value you specified, similar to doing Session.get("foo") == "bar"



Why is it Session.get

good enough !?

What's the point if he's doing something so simple? Meteor uses the idea of ​​reactivity and every time you change the value that the helpers have to rerun.

If you use Session.equals

this ensures that the helper restarts very minimally as the change can only be true

or false

. It was built for the efficiency of your application, so the html doesn't need to be checked and changed.

+7


source


The documentation makes this pretty clear

Session.equals

is for comparing the key value in the session with the provided value, similar Session.get("key") === "compare to value"

. However, the documentation recommends using Session.equals

in this case so that there are fewer redraws.



Session.equals

returns true

or false

based on comparison.

Session.set

actually sets the value for the given key in the session. This is completely different.

+1


source







All Articles