0

Is there a Javascript callback for detecting multiple smartUpdates?

asked 2011-10-12 08:09:40 +0800

gekkio gravatar image gekkio flag of Finland
899 1
http://gekkio.fi/blog

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);
...

(The smartUpdate calls aren't of course sequential in real code but in separate setters)

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.

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2011-10-12 20:10:45 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

Hi,

Please register an onReponse event to do the job when the dirty variable is changed.

You can refer to this example

link publish delete flag offensive edit

answered 2011-10-12 23:24:51 +0800

gekkio gravatar image gekkio flag of Finland
899 1
http://gekkio.fi/blog

Thanks, that's exactly what I'm looking for! :)

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-10-12 08:09:40 +0800

Seen: 378 times

Last updated: Oct 12 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More