lundi 23 février 2015

What's the scope of definition of "persistent state" in EmberJS?

It may sound like a pedantic question. Sorry :)


I have a case like this... here's my router definition:



Router.map(function() {
this.resource('gobernadores', { path: '/gobernadores' }, function() {
this.resource('gobernador', { path: '/:id_estado' }, function() {
this.route('simulacion', { path: '/simulacion' }),
this.route('info', { path: '/info' })
})
});
this.route("login");
this.route("bienvenido");
});


In the "gobernadores" route, I have list of provinces. You can see it's a nested layout. In that same page, we're showing the currently-selected province (that's the gobernador route). Inside the template for that gobernador route, I have a tab, with two elements..., one showing the route "simulacion", and the other one showing the template of route "info" (of that province).


Now, the problem: as user jumps from one province to another province (by clicking the navigation menu on the left side of the screen), I want to keep in memory, the tab that was currently selected, for each province.


So, if the user is currently seeing the result of simulacion of province X, and then he clicks on the link to go to province Y (where he will be presented with "info" of province Y), and then he goes back to province X, I want the app to take the user back to the screen he was seeing (the simulacion of province X).


You can't have that information stored in the controller (GobernadorController), because I can see that controllers can't keep state, it's stateless.


So..., I have to move that info into the model of the route (GobernadorRouteModel)...


My doubt: is it okay? Why my doubt? Because of this: http://ift.tt/17r8Bna


It says:



MODELS


A model is an object that stores persistent state. Templates are responsible for displaying the model to the user by turning it into HTML. In many applications, models are loaded via an HTTP JSON API, although Ember is agnostic to the backend that you choose.


ROUTE


A route is an object that tells the template which model it should display.



This GobernadorRouteModel is not something I persists in the backend. I have no intention to do that. So, am I violating the general advice for a good EmberJS app?


Or in other words: "persistent" here doesn't have to mean "something you save into DB", right? It's just "something you want to keep around..., eventhough only during the session of the app, in the memory".


Thanks in advance, Raka





Aucun commentaire:

Enregistrer un commentaire