This is a migrated thread and some comments may be shown as answers.

Datasource creates items multiple times

0 Answers 142 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 1
Joshua asked on 25 Jan 2012, 11:39 PM
If I do the following:

dataSource.add({ name: "first" });
dataSource.sync();
dataSource.add({ name: "second" });
dataSource.sync();

Then the create url of the datasource is hit twice for the first add, and once for the second add.

I think the reason is that, on the second call to sync(), the response for the first sync has not yet come back from the server, and so the "dirty bit" or whatever tracks this kind of thing is still set on the first item.

What is the recommend way to deal with this problem?

In my actual application, I am only calling sync once, but this bug surfaces whenever the user creates two things in quick succession.

Here are some of the solutions I've thought of:

1. Disable the UI so that the user cannot create two things in quick succession. (I don't want to do this, because it makes the ui less fluid.)
2. Put a queue and semaphore in front of the sync operation. (I don't want to do this because it slows things down.)
3. Modify the added item immediately after calling sync, and hook into the beforeSend callback to cancel the ajax call if the item has been tagged. (I don't want to do this because it's hacky, it requires parsing the request headers, and it breaks batching.)
4. Do the ajax call myself, and use the datasource only for RUD operations (instead of CRUD).
5. Call _accept on the item after calling sync, so that it won't re-post. (I don't want to do this, because it means the data is forever lost if a network error occurs, and besides, calling private functions is bad style.)
6. Fix kendo. (I don't want to do this, but I'm happy to file a bug.)

No answers yet. Maybe you can help?

Tags
Data Source
Asked by
Joshua
Top achievements
Rank 1
Share this question
or