I am gettring rid of my ‘ifEqual’ hacks with computed properties and also wanted to clean up some variable settings.
The problem:
The user can switch between ‘Published’ and ‘Unpublished’, if it’s unpublished he is also able to delete the content. But the ‘Delete’ Button only should be there if he saves the content with ‘unpublished’.
The binding is a problem here, because if I do it with a property like:
I’ve been meeting to figure out a way to inject ember-buffered-proxy into Ember Data Models but just haven’t gotten the time yet. Sounds like you might want something similar. So basically changes made to a Model will not propagate throughout ember until it is saved to the server.
You could look at the isDirty property on the Model. So something like this:
// app/model/foobar.js
import Ember from 'ember';
import DS from 'ember-data';
export default DS.Model.extend({
status: DS.attr('string'),
unpublished: Ember.computed.equal('status', 'unpublished'),
isSaved: Ember.computed.not('isDirty'),
isUnpublished: Ember.computed.and('unpublished', 'isSaved')
});
But it sounds like you are trying to move away from too many computed properties.?.
Tried using ember-buffered-proxy directly on models, haven’t had much success with that. Here’s the approach I’m using (still needs a bit of work to continue working under Ember 2.0):
Thanks @Leeft, I’ll review your stuff in the morning. Bummer on the ember-buffered-proxy, I had some hope…
Just thought of another tactic I’m going to try. Instead of the html form modifying the model directly, I’ll have it modify properties on the controller. Those properties will Ember.computed.oneWay() to the model properties, to get the default/current values. Then on form submit, the action handler will apply the (potentially) changed properties from the controller to the model, try .save()ing the model right away and .rollback() if it fails. Of course there will be a short period where the changes will appear throughout Ember while the changes are saved… Example: JS Bin - Collaborative JavaScript Debugging