What is meteor Session.equals used for?
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.
source to share
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.
source to share