user2398029
user2398029

Reputation: 6937

Model code duplication when using Ember.js

I'm considering switching to Ember.js for one of my Sinatra applications. Our current setup is using server-side Handlebars rendering along with RESTful routes for CRUD operation and Websockets for push notifications.

My main concern, however, is duplication of model code.

Ember Data is a library for loading models from a persistence layer (such as a JSON API), updating those models, then saving the changes. It provides many of the facilities you'd find in server-side ORMs like ActiveRecord, but is designed specifically for the unique environment of JavaScript in the browser.

From what I understand, to use Ember.js, I need to define my models in Javascript, thus duplicating a lot of the Mongo models that we already have server-side. Is this correct? How is it possible to mitigate code duplication in models when using Ember.js in combination with a Ruby backend?

Upvotes: 2

Views: 204

Answers (1)

RyanJM
RyanJM

Reputation: 7068

You will probably want to split up some of the tasks between being done on the client side and being done server side.

The models themselves will be duplicated since it makes it easier to work with Ember if you have Ember Data models. Though, you could build your own models on the fly and just have api calls for everything (probably not advised). You would do that by doing the api calls within the model hook of the route.

Once you have Ember Data models setup though, you could keep your logic fairly simple and have the server to more complicated tasks. But this largely depends on application specific needs.

Upvotes: 3

Related Questions