-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I'm wondering if there's a Javascript callback that Widgets can implement so that I can run custom code after all smartUpdates from a request have been applied?
The basic idea is that I do multiple smart updates in Java code:
... int rows = 10; int cols = 20; smartUpdate("rows", rows); smartUpdate("cols", cols); ...
On the client side I have a component that has the relevant setters. In these setters I refresh the DOM structure if the component is bound to a desktop:
... cols: 0, rows: 0, ... setRows: function(value) { this.rows = value; if (this.desktop) { this.refreshDomStructure(); } } setCols: function(value) { this.cols = value; if (this.desktop) { this.refreshDomStructure(); } } ...
The problem here is that refreshDomStructure is called twice because in setter code it's impossible to know whether the call is the last setter call or not. If refreshDomStructure is an expensive call, this is a very bad thing for performance. In this example there are only 2 setters so it's not that bad. But imagine if there was 10 setters: that would totally destroy the performance of the widget.
Essentially I'd like to have something like this:
dirty: false, ... setRows: function(value) { if (this.rows != value) { this.rows = value; this.dirty = true; } } setCols: function(value) { if (this.cols != value) { this.cols = value; this.dirty = true; } } afterSmartUpdate: function() { if (this.dirty) { this.dirty = false; this.refreshDomStructure(); } } ...
Is there something like that already? I looked at the Javascript API but couldn't find anything like that.
I know that Skippers could be used here but it seems like a very complex approach for such a simple thing.
Hi,
Please register an onReponse event to do the job when the dirty variable is changed.
You can refer to this example
Thanks, that's exactly what I'm looking for! :)
Asked: 2011-10-12 08:09:40 +0800
Seen: 378 times
Last updated: Oct 12 '11