breeze-client / enableSaveQueuing
Function: enableSaveQueuing()
enableSaveQueuing(
em,enable?):void
Defined in: src/mixins/mixin-save-queuing.ts:102
Turns save queuing on or off for one EntityManager.
With it on, a saveChanges call made while another save is still in flight is held back rather than rejected, and sent as a single follow-up save when the first one returns. Each promise resolves with the result of the save that carried its changes.
It also keeps edits made during a save. Without queuing those are overwritten by the server's values when the save result merges back, leaving the entity Unchanged and hasChanges() false - so nothing tells the application that a change was lost. A foreign key set during a save is carried over too: if the parent's row is still being inserted, the queued save substitutes the key the server assigned for the temporary one.
Intended for short-latency auto-save. It is not an offline story, it reuses the first save's SaveOptions, and it does not cope with rejectChanges, export/import or primary-key changes while a save is in flight. Disabling user input for the duration of a save is usually the better answer; this is for applications that cannot.
Parameters
em
The manager to wrap. Its saveChanges is replaced, and restored when disabled.
enable?
boolean = true
false puts the manager's own saveChanges back. Calling this more than once on the same manager, in either direction, is harmless.
Returns
void
Example
import { enableSaveQueuing } from 'breeze-client/mixin-save-queuing';
enableSaveQueuing(em, true);
const first = em.saveChanges(); // sent now
order.shipName = 'changed'; // typed while that save is out
const second = em.saveChanges(); // queued, and sent when the first returnsSee
QueuedSaveFailedError, which every pending promise rejects with if a queued save fails.