After a change in the viewmodel, I want to immediately update the value on the server.
class OrderLine
{
itemCode: KnockoutObservable<string>;
itemName: KnockoutObservable<string>;
constructor(code: string, name: string)
{
this.itemCode = ko.observable(code);
this.itemName = ko.observable(code);
this.itemCode.subscribe(this.updateCode, this, "change");
this.itemName.subscribe(this.updateName, this, "change");
}
updateCode = (newvalue: string) =>
{
//Update value on the server
}
updateName = (newvalue: string) =>
{
//Update value on the server
}
}
Users can change both values, and with explicit subscriptions, updating to the server/database works correctly.
On the server side, updating itemCode
will also update the value of itemName
. Thus, the response to the client will include a json
object with the new value for itemName
The issue arises when changing the value of itemName
in the viewmodel triggers a subscription callback method that updates the same value on the server again
updateCode = (newvalue: string) =>
{
//Update value on the server
//Upon successful request
this.itemName(updatedvaluefromServer);
}
Question: Is it possible to change the value of a KnockoutObservable
that only notifies view subscribers?
Or is there a way to detect if the value was changed from the view?
I attempted to use the "sneaky update" technique by @RPNiemeyer mentioned here
However, this approach suspends notification for all subscribers, including those in the view