Making an Email app with ember, ember-data seems totally useless


#1

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.

  1. I don’t understand the conventions of ember well enough.
  2. Apps like the one I’m writing are not suited for ember.
  3. I’m doing it wrong and I’m an idiot.

Does anyone have any idea what I’m talking about?


#2

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.

Just $0.02. Best of luck :slight_smile:


#3

You can also take a look at various solutions that might help: https://github.com/kurko/ember-sync, https://github.com/nolanlawson/ember-pouch or https://github.com/gr2m/ember-hoodie-adapter. Oh and there is also https://github.com/genkgo/ember-localforage-adapter which might help for better cross-browser support. Hope that helps.


#4

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.


#5

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.


#6

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.


#7

Perhaps you can sync your mail to CouchDB on the backend and use Ember-Pouch on the frontend. I use Ember-Pouch here: https://github.com/broerse/ember-cli-blog