Last active
June 3, 2016 07:39
-
-
Save kumkanillam/bf7f55f632d4b3035c7fba4b1f632918 to your computer and use it in GitHub Desktop.
Ember-data- HasMany Not triggering computed properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
name: DS.attr('string'), | |
days: DS.hasMany('day'), | |
dates: Ember.computed('days.@each', function () { | |
console.log("dates computed in calendar model "); | |
return this.get('days').map(day => day.get('date')); | |
}) | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
date: DS.attr('string'), | |
calendar: DS.belongsTo('calendar') | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
beforeModel(){ | |
this._super(...arguments); | |
$.mockjax({ | |
url: '/calendars', | |
type: 'GET', | |
responseText:{ | |
"data": [{ | |
"type":"calendar", | |
"id":1, | |
"attributes": { | |
"id":1, | |
"name":"first calendar", | |
"days":[2,3], | |
}, | |
"relationships": { | |
"days": { | |
"data":[ | |
{"id":2,"type":"day"}, | |
{"id":3,"type":"day"} | |
] | |
} | |
} | |
}, | |
{ | |
"type":"day", | |
"id":2, | |
"attributes":{ | |
"id":2, | |
"calendar":1, | |
"date":"2016-06-15" | |
} | |
}, | |
{ | |
"type":"day", | |
"id":3, | |
"attributes":{ | |
"id":3, | |
"calendar":1, | |
"date":"2016-06-17" | |
} | |
}] | |
} | |
}); | |
$.mockjax({ | |
url: '/red', | |
type: 'GET', | |
responseText:{'one':1} | |
}); | |
$.mockjax({ | |
url: '/days', | |
type: 'GET', | |
responseText:{ | |
"data":[{ | |
"type":"day", | |
"id":2, | |
"attributes":{ | |
"id":2, | |
"calendar":1, | |
"date":"2016-06-15" | |
} | |
}, | |
{ | |
"type":"day", | |
"id":3, | |
"attributes":{ | |
"id":3, | |
"calendar":1, | |
"date":"2016-06-17" | |
} | |
}] | |
} | |
}); | |
}, | |
model(){ | |
return this.store.findAll('calendar'); | |
}, | |
afterModel(resolvedModel,transition){ | |
this._super(...arguments); | |
console.log("resolvedmodel"); | |
console.log(resolvedModel); | |
}, | |
setupController(){ | |
this._super(...arguments); | |
console.log('setupcontroller'); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.8.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"jquery-mockjax":"https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.min.js", | |
"ember": "2.5.1", | |
"ember-data": "2.5.2", | |
"ember-template-compiler": "2.5.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment