Opened 7 years ago

Closed 7 years ago

#14763 closed defect (fixed)

dojox.mvc StatefulModel can not add new data which the same with already delete one

Reported by: Eric Wang Owned by: Ed Chatelain
Priority: undecided Milestone: 1.8
Component: DojoX MVC Version: 1.7.1
Keywords: todoapp Cc:
Blocked By: Blocking:

Description

One of the issue is dojox.mvc data model commit issue, you can put the files below in demos/todoMvcApp directly to override the original ones to reproduce the issue.
I just find the root cause of this issue:

  1. ItemFileWriteStore? can delete an item and add the same data to store again (click "test model" button in demo.html)
  2. dojox.mvc StatefulModel? can remove an item from the store but cannot add the some data back to the store, the error is "uncaught Erro: assertion failed in ItemFileWriteStore?" (click "test mvc model" button for test)

root cause: ItemFileWriteStore? will call its save method to save the data change, it first add the deleted item to a temporary delete array, when the data store successful, it will clean the temporary delete array. dojox.mvc StatefulModel? remove an item will put it in a temporary remove array and the store automatic put the item in a temporary delete array, if the user calls commit(), it will save the change and apply the change to data store, however the apply not clean store's temporary delete array. If the user adds the same data to data model again, it will throw the assertion failed error for the data already exist in delete array.

Another issue is if I have two dojox.mvc StatefulModel? data model call model1 and model2, I cannot directly remove model1's item item0 (for example: item0) and add item0 to model2, because model2's commit will change item0's value, you can see in the demo.html test (click "test mvc model" button for test), I cloned the data and add to model2. I wander to know if dojox.mvc can support directly remove one item and add to another data model?

Attachments (2)

src.js (13.3 KB) - added by Eric Wang 7 years ago.
demo.html (6.1 KB) - added by Eric Wang 7 years ago.

Download all attachments as: .zip

Change History (8)

Changed 7 years ago by Eric Wang

Attachment: src.js added

Changed 7 years ago by Eric Wang

Attachment: demo.html added

comment:1 Changed 7 years ago by cjolif

Keywords: todoapp added

comment:2 Changed 7 years ago by Ed Chatelain

Well the problem is that StatefulModel? takes a dojo.store.DataStore?, you are wrapping an ItemFileWriteStore? in a dojo.store.DataStore?. ItemFileWriteStore? requires a call to save() before an item which has been deleted can be added again, but dojo.store.DataStore? does not have a save function or a way to call save on the ItemFileWriteStore?. One solution would be for the app (src.js) to call datamodel.store.store.save(); after the call to remove and commit anytime an item may be added back again, like this:

		datamodel = itemsmodel[0];
		datamodel.remove(0);
		datamodel.commit();
		datamodel.store.store.save();

There may be a better solution, but this will work.

The point is StatefulModel? can not call save since it is not available on the DataStore?.

comment:3 Changed 7 years ago by cjolif

I agree the StatefulModel can not call save because this is not a dojo/store but a dojo/data API. However shouldn't DataStore which wrap a dojo/data in a dojo/store do this? Otherwise the wrapper is useless as at some point you'll have to go back to the wrapped object and use its API instead of using the wrapped API?

Last edited 7 years ago by cjolif (previous) (diff)

comment:4 Changed 7 years ago by Kris Zyp

Resolution: fixed
Status: newclosed

In [28225]:

Call save() on data stores after modifications, fixes #14763 !strict

comment:5 Changed 7 years ago by Kris Zyp

Resolution: fixed
Status: closedreopened

Er, I guess I shouldn't have marked that as "fixes", since I didn't actual test dojox.mvc, just fixed the issue that edchat pointed out.

comment:6 Changed 7 years ago by Ed Chatelain

Milestone: tbd1.8
Resolution: fixed
Status: reopenedclosed

Thanks Kris, your fix worked.

For future reference, I did find a bug in the testcase, where it was calling hasClass on a node after it was deleted, once that was fixed along with the fix from Kris, there was no problem adding the item back after it was deleted.

Note: See TracTickets for help on using tickets.