Created
January 10, 2020 20:25
-
-
Save GCheung55/7cb7364575c19b582701f96d3e23add6 to your computer and use it in GitHub Desktop.
New Twiddle
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 { inject as service } from '@ember/service'; | |
import { filterBy } from '@ember/object/computed'; | |
export default Ember.Controller.extend({ | |
store: service(), | |
appName: 'Ember Twiddle', | |
programTags: filterBy('model.program.tags', 'id', true) | |
actions: { | |
deleteTag(tag) { | |
tag.unloadRecord(); | |
} | |
} | |
}); |
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({ | |
title: attr('string'), | |
tags: hasMany('tag') | |
}); |
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({ | |
name: attr('string'), | |
programs: hasMany('program') | |
}); |
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 { inject as service } from '@ember/service'; | |
export default Ember.Route.extend({ | |
store: service(), | |
beforeModel() { | |
this.store.pushPayload({ | |
data: [ | |
{ | |
type: 'program', | |
id: 1, | |
attributes: { | |
title: 'Program 1!' | |
}, | |
relationships: { | |
tags: { | |
data: [{type: 'tag', id: 1}, {type: 'tag', id: 3}] | |
} | |
} | |
}, | |
{ | |
type: 'tag', | |
id: 1, | |
attributes: { name: 'foo' } | |
}, | |
{ | |
type: 'tag', | |
id: 2, | |
attributes: { name: 'bar' } | |
}, | |
{ | |
type: 'tag', | |
id: 3, | |
attributes: { name: 'baz' } | |
} | |
] | |
}) | |
}, | |
model() { | |
return { | |
program: this.store.peekRecord('program', 1), | |
allTags: this.store.peekAll('tag') | |
} | |
} | |
}); |
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.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.4.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment