Skip to content

Instantly share code, notes, and snippets.

@boffbowsh
Created December 30, 2014 00:48
Show Gist options
  • Save boffbowsh/9f97307999b7311a6143 to your computer and use it in GitHub Desktop.
Save boffbowsh/9f97307999b7311a6143 to your computer and use it in GitHub Desktop.
Set a form to use the shadowModel of the controller, and changes won't be saved back to the model (and your list-of-models next to the form) until you call `save()`. Will probably break with relationships, that'll need fixing.
{{#em-form model=shadowModel}}
{{em-input property="name" label="Name"}}
{{em-input property="slug" label="Slug"}}
{{/em-form}}
import Ember from 'ember';
import ShadowController from 'shadow-controller';
export default Ember.ObjectController.extend(ShadowController, {
});
import Ember from 'ember';
export default Ember.Mixin.create({
_shadowedProperties: [],
shadowModel: function() {
var shadow = Ember.Object.create();
this.get("model").eachAttribute((name) => {
this._shadowedProperties.push(name);
shadow.set(name, this.get("model").get(name));
});
return shadow;
}.property("model"),
save: function() {
var properties = this.get("shadowModel").getProperties(this._shadowedProperties);
this.get("model").setProperties(properties);
this.get("model").save();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment