Last active
June 20, 2017 09:17
-
-
Save pswai/6acfc32d3e1984496bd281a279d6fbd2 to your computer and use it in GitHub Desktop.
Evaluate ember-changeset
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 Changeset from 'ember-changeset'; | |
export default Ember.Controller.extend({ | |
pojo: { | |
foo: 123, | |
bar: 456, | |
baz: Ember.Object.create() | |
}, | |
pojoChangeSet: Ember.computed('pojo', function () { | |
const pojo = this.get('pojo'); | |
return new Changeset(pojo); | |
}), | |
pojoNested: { | |
foo: 123, | |
inner: { | |
bar: 456 | |
} | |
}, | |
pojoNestedChangeSet: Ember.computed('pojoNested', function () { | |
const pojoNested = this.get('pojoNested'); | |
return new Changeset(pojoNested); | |
}), | |
dsModel: Ember.computed(function () { | |
const store = this.get('store'); | |
const bar = store.createRecord('bar', { | |
name: 'bar' | |
}); | |
return store.createRecord('foo', { | |
name: 'foo', | |
inner: Ember.Object.create(), | |
bar | |
}); | |
}), | |
dsModelChangeSet: Ember.computed('dsModel', function () { | |
const dsModel = this.get('dsModel'); | |
return new Changeset(dsModel); | |
}), | |
actions: { | |
rollback(changeSet) { | |
changeSet.rollback(); | |
}, | |
save(changeSet) { | |
changeSet.save(); | |
}, | |
changeObject(changeSet, path) { | |
changeSet.set(path, Ember.Object.create()); | |
}, | |
changeRelationship(changeSet, path, model) { | |
const instance = this.get('store').createRecord(model, { | |
name: `${model} (created ${Date.now()})` | |
}); | |
changeSet.set(path, instance); | |
} | |
} | |
}); |
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 DS from 'ember-data'; | |
export default DS.Model.extend({ | |
name: DS.attr('string'), | |
inner: DS.attr(), | |
bar: DS.belongsTo('bar') | |
}); |
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({ | |
}); |
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.12.1", | |
"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.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1", | |
"ember-changeset": "1.3.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment