mercredi 28 janvier 2015

Need a strategy for implemeningt a partial update service call without re-inventing the wheel

My backend has some cool functionality that I'm struggling with implementing. Easier to explain with an example...


Say you have an order, with order lines (defined as hasMany) and products attached that the user is currently editing and they change the price on a line. Functionally you'd want to recalculate the sales tax as an example.


My backend allows me to package-up and send this transient object (along with a list of changed fields) and will determine what needs to be altered on the object tree (without actually persisting that object yet). What it returns is a sparsely-populated object with the values that have been changed server-side.


So, if I have something like this:



{
orderid: '12345',
taxamt: 0,
lines: [
{
id: 1,
product: 'ABC',
price: 99.99
}
]
}


And then let's say, the user updates the line price. If I send this to the backend:



{
orderid: '12345',
taxamt: 0,
lines: [
{
id: 1,
product: 'ABC',
price: 89.99
}
],
changelist: ['lines.price']
}


... I'll get back something like this:



{
orderid: '12345',
taxamt: 12.00,
}


...that is, I'll get enough to uniquely identify each object and then only the properties that were updated server-side.


I've got the first half of this implemented, but handling the return is proving to be difficult. I've got it partially working but it sure feels like I'm re-implementing a ton of what ember data is already doing.


Given that the server may add or delete relationship objects and may alter any property at any level, what's a good approach that leverages the existing framework the best?





Aucun commentaire:

Enregistrer un commentaire