Hi, we are currently attempting to write an email application with Ember. We are running into a few problems.
We want the emails that are loaded to persist even after the user hits refresh.
We used the REST.Adapter to fetch the data and then stored it in sessionStorage.
I understand its not best practice to use REST and LS.Adapter in the same model but we don’t know how else to do it.
Doing this makes ember-data models seem useless. Now every time we access the data, its directly from local storage.
There are a few things I could take away from this.
I don’t understand the conventions of ember well enough.
Apps like the one I’m writing are not suited for ember.
Having an ember-data model manage three representations of your object (server, memory, localStorage) seems problematic from a design POV even if ember-data could be persuaded to do it (which I think it could).
How often is email pulled down from server? Is it ever written back up to the server? Perhaps having a service/controller to manage the sync of server to localStorage would be worth exploring since you will be reading/writing JSON for both of those “storage places” i.e. it is a String → String operation and probably(?) doesn’t require much interpretation of the data(YMMV). Then you can use ember-data models to represent the localStorage data to the rest of the app.
If you are storing your data in sessionStorage, you can setup a initializer that checks if there is any data, and then do store.pushPayload to populate all of your models before your page initializes. Make sure to use after: 'store' for the initializer, and get the store from the container.
How often is email pulled down from server?
As often as the user refreshes. We are also working on push from the server side so we don’t have to poll.
Is it ever written back up to the server?
Yes it is. The client side is just and interface to the mailserver.
Perhaps having a service/controller to manage the sync of server to localStorage would be worth exploring since you will be reading/writing JSON for both of those “storage places” i.e. it is a String → String operation and probably(?) doesn’t require much interpretation of the data(YMMV). Then you can use ember-data models to represent the localStorage data to the rest of the app.
Could you elaborate a bit more on this? I don’t quite understand.
I think the question is if we should be storing it in sessionStorage in the first place. Currently we are using both sessionStorage and ember-data storage.