I am attempting to send a dirty record to the clean state manually (in relation to How to manually set an object state to clean (saved) using ember-data).
I've stumbled across something that may be happening because of undesirable use of ember-data or a bug.
Basically, what I do is
- find the record in question,
.set()
a property on the record, and- send the record to the 'becameClean' state manually. This is done in order to avoid having the record being committed when calling
App.store.commit();
for reasons mentioned in the question linked to in the above.
Before we begin, I have added an enter: function() { console.log(this); console.log(this.get('path')); }
line to the DS.State = ...
part of ember-data in order to see which states the record goes through.
I'm running the very latest pull off of GitHub. Here's my approach:
Step 1) Call App.Fruit.find('banana');
:
console.log(this);
results in:<DS.State:ember1077> { initialState="saved", isLoaded=true, saved=<DS.State:ember1078>, more...}
console.log(this.get('path'));
results in:- 'rootState.empty'
- 'rootState.loading'
- 'rootState.loaded'
- 'rootState.loaded.saved'
Step 2) Call App.Fruit.find('banana').set('description', 'Yellow fruit!');
:
console.log(this);
results in:<(subclass of DS.State):ember1084> { dirtyType="updated", childStates=[3], eventTransitions={...}, more...}
console.log(this.get('path'));
results in:- 'rootState.loaded.updated'
Step 3) Call App.store.get('defaultTransaction.buckets');
:
- results in the record appearing in the 'updated' bucket
Step 4) Call App.Fruit.find('banana').get('stateManager').send('becameClean');
:
console.log(this);
results in:<DS.State:ember1078> { childStates=[0], eventTransitions={...}, states={...}, more...}
console.log(this.get('path'));
results in:- 'rootState.loaded.saved'
Step 5) Call App.store.get('defaultTransaction.buckets');
:
- results in the record appearing in the 'clean' bucket
Intermission: Okay, so far, so good. It appears that I've successfully sent the record to the clean state. However, this happens:
Step 6) Call App.Fruit.find('banana').set('description', 'Even more yellow fruit!');
:
console.log(this);
results in:(nothing)
console.log(this.get('path'));
results in:(nothing)
Step 7) Call App.store.get('defaultTransaction.buckets');
:
- results in the record appearing in the 'clean' bucket
The problem is that after I've sent the 'becameClean' state to the record, it stays in the 'loaded.saved' state no matter if I change the record afterwards.
When step 2 resulted in a new subclass object of DS.State
being created with a dirtyType="updated"
, how come step 6 doesn't result in this too?
My question is: is this a bug or does it not work because my use of .send('becameClean')
is undesirable?