Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict Handling? #149

Closed
ronag opened this issue May 14, 2016 · 4 comments
Closed

Conflict Handling? #149

ronag opened this issue May 14, 2016 · 4 comments

Comments

@ronag
Copy link

ronag commented May 14, 2016

I've started looking into deep stream and the core issue I'm having is how to handle conflicts? e.g. I'm looking for something like https://www.firebase.com/docs/web/api/firebase/transaction.html or https://github.com/pouchdb/upsert.

@WolframHempel
Copy link
Member

WolframHempel commented May 14, 2016

Hi @ronag,

pull requests #137 on the server and #105 for the JS client are currently under review, adding exactly the functionality that you describe. They will allow clients to specify a merge strategy that will be executed on conflict, both globally and on a per-record basis. You can find more details in this issue. Please let me know if this fulfills what you are looking for.

@ronag
Copy link
Author

ronag commented May 14, 2016

@WolframHempel: Almost. I would like to have an API where the update can be easily retried against the server. As far as I can see the suggested changes are just to resolve conflicts on the client side not actually performing a server side transaction.

@WolframHempel
Copy link
Member

if I'm not mistaken, that's very much what this will be:

myRecord.setMergeStrategy(function( remoteValue, recordName, callback ) {
    var localValue = ds.record.getRecord( recordName );
    //do your merging, then retry
    callback( error, mergedVersion );
});

@yasserf
Copy link
Contributor

yasserf commented May 14, 2016

That's correct, the merged version that is returned will be set onto the record as an update and sent to the server. If the merge conflict fails again the client will be notified, until it works. This is similar to how the transaction works.

Only thing that's different is the api, which is:

myRecord.setMergeStrategy(function( record, remoteValue, remoteVersion, callback ) {
    var localValue = ds.get();
    //do your merging, then retry
    callback( error, mergedVersion );
});

This stops users from having to remember to discard the record, and also reduces what would have been a pretty long argument list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants