Add support for concurrency conflicts on a array item level - AndersMalmgren/Knockout.Concurrency GitHub Wiki
The getting started example does not support scenarios where items have been removed or added. To support this the engine needs to know a little more about your model. You do this by supplying a mapping literal to the runner
var mappings = {
children: {
key: function(item) {
return ko.utils.unwrapObservable(item.id);
},
create: function(data) {
return { id: data.id, name: data.name };
}
}
};
this.concurrencyRunner.run(this, data, mappings);
- key: used by the engine to match the rows
- create: used by the engine to create new rows
- deleted: When a existing row is deleted on the server the Id will not exist anymore in the DB. You can use the deleted method to reflect this
deleted: function(item) {
item.id(0);
}
This way if your user choose to take his local version to resolve a conflict, backend will create a new row instead of throwing a Constraint error (This can off course also be addressed server side, but the option is there to fix it client side)