Created
May 24, 2019 00:54
-
-
Save sdhull/ce94fe23e75769a4a4c3b08555bd564c 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 { computed } from '@ember/object'; | |
const nsfw = ['nudity', 'violence', 'vulgarity', 'drug use', 'socialism', 'dangerous ideas']; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
nsfwTags: computed('post.tags.nsfw.[]', function() { | |
return this.post.get('tags.nsfw'); | |
}), | |
init() { | |
this._super(...arguments); | |
let tag = this.store.createRecord('tag', {name: nsfw[Math.floor(Math.random() * nsfw.length)]}); | |
this.post = this.store.createRecord('post', {title: 'hihihi', 'tags.nsfw': [tag]}); | |
}, | |
actions: { | |
addATag() { | |
let tag = this.store.createRecord('tag', {name: nsfw[Math.floor(Math.random() * nsfw.length)]}); | |
this.post.get('tags.nsfw').pushObject(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({ | |
title: attr('sting'), | |
body: attr('string'), | |
tags: hasMany('tag'), | |
'tags.nsfw': hasMany('tag', {inverse: null}), | |
}); |
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'), | |
posts: hasMany('post'), | |
}); |
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