Meteor Pattern State vs. Global Session

I'm just starting with the meteor shower coming from the Apache-Wicket object-oriented development.

How to understand, if the data used in the template is not a mongodb document, the session should be used to store status information, for example. drop down selection. But the session is global, and if the template is used twice or several times, then the fixed session mySelection property does not work, since all template instances will share / redefine the same session value. Apache Wicket's solution is to use the fullqualified template-path to prefix the property and maintain a unique session property for each instance of the template.

Is there a general built-in solution to support "instance-template state" in a meteor? If not, is it possible that the instance template itself is somehow accessible from the template functions?

+4
source share
2 answers

The way I do this is similar to what you describe as an Apache Wicket solution, except that I would write my own code to control it. So, for example, manage session objects with keys corresponding to each template:

function setTemplateSession(key, value) { Session.set("template_" + key, value); } function getTemplateSession(key) { Session.get("template_" + key); } 

In your template methods:

 Template.myList.selection = function() { return getTemplateSession("myList"); } Template.myOtherList.selection = function() { return getTemplateSession("myOtherList"); } 

You could obviously distract this even further. Although it would be nice if Meteor provided this default behavior, maybe instead of looking for Meteor for this, could you write a smart package that introduces the Apache Wicket philosophy into the Meteor template system?

+1
source

The template instance itself is available through it.

See Template Instances .

-1
source

All Articles