Forked from korneev-andrew/controllers.application\.js
Last active
November 18, 2020 14:06
-
-
Save lifeart/ed259f439203096ac88c0e0aaa3383f1 to your computer and use it in GitHub Desktop.
Pushing new meta-attr
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 Controller from '@ember/controller'; | |
import { action } from '@ember/object'; | |
import { inject as service } from '@ember/service'; | |
export default class ApplicationController extends Controller { | |
appName = 'Ember Twiddle'; | |
@service('store') store; | |
constructor() { | |
super(...arguments); | |
this.setup(); | |
} | |
@action setup() { | |
this.store.pushPayload({ | |
included: [ | |
{id: '1', type: 'meta-attribute', attributes: { value: 'a', name: 'firstname' } }, {id: '2', type: 'meta-attribute', attributes: { value: 'b', name: 'lastname' } } | |
], | |
data: { | |
id: '1', | |
type: 'meta-model', | |
relationships: { | |
'meta-attributes': { | |
data: [ | |
{id: '1', type: 'meta-attribute'}, | |
{id: '2', type: 'meta-attribute'}, | |
] | |
} | |
} | |
} | |
}); | |
this.set('items', this.store.peekAll('meta-model')); | |
} | |
@action pushMetaAdditive() { | |
this.store.createRecord('meta-additive', { parent: this.store.peekAll('meta-attribute').firstObject }); | |
} | |
@action pushMetaAttribute() { | |
const model = this.store.peekRecord('meta-model', '1'); | |
this.store.createRecord('meta-attribute', { | |
id: Date.now().toString(), | |
value: 'c', | |
name: 'middlename', | |
parent: model, | |
}); | |
} | |
} |
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 { belongsTo } from 'ember-data/relationships'; | |
export default class extends Model { | |
@belongsTo('meta-attribute', { async: false, polymorphic: true, inverse: 'additives' }) | |
parent; | |
} |
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'; | |
import { alias } from '@ember/object/computed'; | |
export default class extends Model.extend({ | |
countAdditives: alias('additives.length'), | |
}) { | |
@attr('string') value; | |
@attr('string') name; | |
@belongsTo('meta-model', { async: false, polymorphic: true, inverse: 'metaAttributes' }) | |
parent; | |
@hasMany('meta-additive', { async: false, polymorphic: true, inverse: 'parent' }) | |
additives; | |
} |
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 { belongsTo, hasMany } from 'ember-data/relationships'; | |
import EmberObject, { computed, defineProperty, get } from '@ember/object'; | |
import { alias } from '@ember/object/computed'; | |
export default class extends Model.extend({ | |
allAdditives: computed('[email protected]', function(){ | |
return this.metaAttributes.toArray().reduce((acc, el)=>{ | |
return acc.concat(el.additives.toArray()); | |
}, []); | |
}) | |
}) { | |
@hasMany('meta-attribute', { async: false, inverse: 'parent', polymorphic: true }) | |
metaAttributes; | |
} |
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.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.12.0", | |
"ember-template-compiler": "3.13.0", | |
"ember-testing": "3.13.0" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0", | |
"ember-data": "3.12.5" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment