Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4827

How to use ember-data with mixin?

$
0
0

@Jeffrey_Cheung wrote:

Hello, suppose I am making a RPG, and a character can use an ablilty. My server api is rails, having a Ability class, and including 2 modules, Targetable and Attackable.

Base on the setting on rails, I have a model file in Ember:

import DS from 'ember-data';
export default DS.Model.extend({
  name : DS.attr('string'),
  cost : DS.attr('number'),
});

After that I have 2 mixins for this ablilty class:

import Ember from 'ember';

export default Ember.Mixin.create({
  targetable: DS.attr('boolean'),
});


import Ember from 'ember';

export default Ember.Mixin.create({
  attackable: DS.attr('boolean'),
  damage: DS.attr('number'),
  damageType: DS.attr('string'),
});

However when I get an ablilty from server, ember-data does not know which Mixin to include. My thought is that I can do it in serializer normalize function, but I am not 100% sure.

How to let ability serializer to know which mixin to include? Thank you.

BTW how to highlight my example in JS style?

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4827

Trending Articles