As we mentioned in part two, we need to optimize the code so as to remove Bindable meta data tag. The bindable code generates lot of bloat code. We can optimize this by removing the Bindable tag and using BindableUtils or ChangeWatcher.
We can bind only price property of the stock value object and can make the stock non-bindable.
Another optimization in the above case is to keep all the properties non-bindable and take care of notifying the view (datagrid) when data changes in our hand. In this case class will be same as:
We can bind only price property of the stock value object and can make the stock non-bindable.
public class NonBindableStock { public var ticker:String; public var company:String; [Bindable] public var price:Number; public function NonBindableStock(comp:String, tick:String, prc:Number) { this.price = prc; this.ticker = tick; this.company = comp; } }We can also make use of bindProperty method of BindingUtils and get hold of ChangeWatcher instance. We can remove the binding by calling unwatch() when we do not need it any more. This is straightforward and I am not giving any example for it.
Another optimization in the above case is to keep all the properties non-bindable and take care of notifying the view (datagrid) when data changes in our hand. In this case class will be same as:
public class NonBindableStock { public var ticker:String; public var company:String; public var price:Number; public function NonBindableStock(comp:String, tick:String, prc:Number) { this.price = prc; this.ticker = tick; this.company = comp; } }Now when we change the price we also notify the view by calling itemUpdated() method. So we rewrite the method findAndUpdateNonBindableStock as:
private function findAndUpdateNonBindableStock(ticker:String, updatedPrice:Number):void
{
var nonBindableStock:NonBindableStock = nonBindableStocksDictionary[ticker] as NonBindableStock;
nonBindableStock.price = updatedPrice;
nonBindableStocks.itemUpdated(nonBindableStock);
}
This will now update the view as well and we have removed the overhead of binding as well. I have optimized our stock ticker application and I hope you enjoyed this post. Let me know your feedback.