I have a use case where I don’t want bindings updated until a model successfully saves, but I’ve noticed a lot of the buffering advice out there uses an empty Ember.Object as the buffer. Does using a dummy model of the type being buffered make any sense? Would an approach like this (admittedly naive) first stab at a controller mixin be setting me up for a big pile of regrets down the line? I really want to keep the error clearing behavior as the form fields are changed.
import Ember from 'ember';
export default Ember.Mixin.create({
buffer: function(){
var model = this.get('model');
var buffer = this.store.createRecord(model.constructor.typeKey)
model.eachAttribute(function(name, meta) {
buffer.set(name, model.get(name));
});
console.log(buffer)
return buffer;
}.property('model'),
setModelFromBuffer: function(){
var model = this.get('model'),
buffer = this.get('buffer');
model.eachAttribute(function(name, meta){
var attrib = buffer.get(name);
//if (attrib){
model.set(name, attrib);
//}
});
},
pristineModel: function(){
var model = this.get('model'),
buffer = this.get('buffer');
model.get('errors').toArray().forEach(function(error){
buffer.get('errors').add(error.attribute, error.message)
});
model.rollback();
}
});