Thursday, March 6, 2014

Sapphire 8 : Event Suspension

Model events can now be suspended while performing a multi-step operation. This can be helpful in avoiding distracting flashing of the UI as the model goes through the intermediate states.

Element
{
    /**
     * Suspends all events related to this element and everything beneath it in the model tree. The suspended
     * events will be delivered when the suspension is released.
     * 
     * @return a handle that must be used to release the event suspension
     */
    
    Disposable suspend()
}
Property
{
    /**
     * Suspends all events related to this property and everything beneath it in the model tree. The suspended
     * events will be delivered when the suspension is released.
     * 
     * @return a handle that must be used to release the event suspension
     */
    
    Disposable suspend()
}
final ElementList<PurchaseOrderEntry> entries = po.getEntries();
final Disposable suspension = entries.suspend();

try
{
    final PurchaseOrderEntry entry = entries.insert();
    entry.setItem( "USB Cable" );
    entry.setQuantity( 2 );
    entry.setUnitPrice( "2.5" );
}
finally
{
    suspension.dispose();
}

No comments: