Created
December 30, 2014 00:48
-
-
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.
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 ShadowController from 'shadow-controller'; | |
export default Ember.ObjectController.extend(ShadowController, { | |
}); |
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'; | |
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