Last active
July 21, 2018 00:08
-
-
Save kjhangiani/a33872a20ef7b7279c6a6566132564cb to your computer and use it in GitHub Desktop.
ember polymorphic sideload
This file contains 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'; | |
import ActiveModelAdapter from 'active-model-adapter'; | |
export default ActiveModelAdapter.extend({ | |
}); |
This file contains 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', | |
posts: Ember.A(), | |
comments: Ember.A(), | |
actions: { | |
clear() { | |
this.store.unloadAll('post'); | |
this.store.unloadAll('comment'); | |
this.set('model', null); | |
}, | |
getPost(id) { | |
this.set('model', this.store.peekRecord('post', id)); | |
}, | |
loadPosts() { | |
this.store.pushPayload({ | |
posts: [ | |
{ id: 1, name: 'Post 1' } | |
] | |
}); | |
this.set('posts', this.store.peekAll('post')); | |
console.log('pushed post into store'); | |
}, | |
loadComments() { | |
this.store.pushPayload({ | |
comments: [ | |
{ id: 1, commentable_id: 1, commentable_type: 'Post' }, | |
{ id: 2, commentable_id: 1, commentable_type: 'Post' }, | |
] | |
}); | |
this.set('comments', this.store.peekAll('comment')); | |
console.log('pushed comments into store'); | |
}, | |
} | |
}); |
This file contains 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'; | |
import DS from 'ember-data'; | |
export default Ember.Mixin.create({ | |
comments: DS.hasMany('comment', { async: false }), | |
}); |
This file contains 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({ | |
commentableType: attr('string'), | |
commentableId: attr('number'), | |
commentable: belongsTo('commentable', { polymorphic: true, async: true }), | |
}); |
This file contains 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"; | |
import Commentable from 'twiddle/mixins/commentable'; | |
export default Model.extend(Commentable, { | |
name: attr('string') | |
}); |
This file contains 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.13.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.16.2", | |
"ember-template-compiler": "2.16.2", | |
"ember-testing": "2.16.2" | |
}, | |
"addons": { | |
"active-model-adapter": "2.1.1", | |
"ember-data": "3.3.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment