vendredi 31 juillet 2015

Design models in EmberJS

I have stuck with architectural problem in EmberJS. I already have backend and I need to implement frontend part. So, I have "builder" route:

import Ember from 'ember';

export default Ember.Route.extend({
    model() {
        return this.store.createRecord('builder');
    }
});

Builder model:

import DS from 'ember-data';

export default DS.Model.extend({
    cocktailsTypes: DS.attr(), //must be array
    cocktailsOptions: DS.attr(), //must be array
    selectedIngredients: DS.attr(), //must be array
    ingredients: Ember.computed({
        get() {
            return this.store.findAll('ingredient');
        }
    })
});

"Ingredient" model:

import DS from 'ember-data';

export default DS.Model.extend({
  name: DS.attr('string'),
  vol: DS.attr('number'),
  description: DS.attr('string'),
  category: DS.attr('string')
});

And I want to add some action in "builder" route to create custom request and send data from "builder" model.

Will it work? Is it right way in EmberJS and ember data? Maybe I need to use some alternatives of ember data or change model's design?

My goal is build working app in "ember way" as best as possible.

P.S. I'm using the last version of EmberJS.




Aucun commentaire:

Enregistrer un commentaire