Last active
July 20, 2018 13:05
-
-
Save IgorKvasn/a1db4f46721b8fd631eedee6d7a6d705 to your computer and use it in GitHub Desktop.
model bug
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', | |
store: Ember.inject.service(), | |
init(){ | |
this._super(...arguments); | |
let entity = | |
this.store.pushPayload({ | |
data: { | |
// primary data for single record of type `Person` | |
id: '1', | |
type: 'entity', | |
attributes: { | |
b: 42 | |
} | |
} | |
}) | |
console.log(entity.get('rel.isDirty')); | |
} | |
}); |
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 { isPresent } from '@ember/utils'; | |
import { get } from '@ember/object'; | |
import Mixin from '@ember/object/mixin'; | |
export default Mixin.create({ | |
isModelDirty() { | |
let changed = Object.keys(this.changedAttributes()); | |
let isDirty = false; | |
get(this.constructor, 'attributes').forEach(attr =>{ | |
if (attr.isAttribute === true && isPresent(attr.options) && attr.options.ignoreDirty !== true){ | |
if (changed.includes(attr.name)){ | |
isDirty = true; | |
} | |
} | |
}); | |
return isDirty; | |
} | |
}); |
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 { getOwner } from '@ember/application'; | |
export default Model.extend({ | |
rel: belongsTo('entity2'), | |
ready(){ | |
this._super(...arguments); | |
let store = getOwner(this).lookup('service:store'); | |
this.set('rel', store.createRecord('entity2')); | |
this.set('rel.isDirty', false); | |
} | |
}); |
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 { getOwner } from '@ember/application'; | |
import ModelDirtyMixin from "../mixins/model-dirty-mixin"; | |
import { computed } from '@ember/object'; | |
export default Model.extend(ModelDirtyMixin,{ | |
hello:attr('string'), | |
rel2: belongsTo('entity3'), | |
isDirty: computed(function () { | |
return this.isModelDirty(); | |
}).volatile(), | |
ready(){ | |
this._super(...arguments); | |
let store = getOwner(this).lookup('service:store'); | |
this.set('rel2', store.createRecord('entity3')); | |
this.set('rel2.isDirty', false); | |
} | |
}); |
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({ | |
a: attr('string') | |
}); |
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 { run } from '@ember/runloop'; | |
export default function destroyApp(application) { | |
run(application, 'destroy'); | |
} |
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 Resolver from '../../resolver'; | |
import config from '../../config/environment'; | |
const resolver = Resolver.create(); | |
resolver.namespace = { | |
modulePrefix: config.modulePrefix, | |
podModulePrefix: config.podModulePrefix | |
}; | |
export default resolver; |
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'; | |
import Application from '../../app'; | |
import config from '../../config/environment'; | |
const { run } = Ember; | |
const assign = Ember.assign || Ember.merge; | |
export default function startApp(attrs) { | |
let application; | |
let attributes = assign({rootElement: "#test-root"}, config.APP); | |
attributes = assign(attributes, attrs); // use defaults, but you can override; | |
run(() => { | |
application = Application.create(attributes); | |
application.setupForTesting(); | |
application.injectTestHelpers(); | |
}); | |
return application; | |
} |
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 resolver from './helpers/resolver'; | |
import { | |
setResolver | |
} from 'ember-qunit'; | |
import { start } from 'ember-cli-qunit'; | |
setResolver(resolver); | |
start(); |
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.15.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "2.18.0", | |
"ember-template-compiler": "3.2.2", | |
"ember-testing": "3.2.2" | |
}, | |
"addons": { | |
"ember-data": "3.3.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment