Is there any concept of destructors for zebra components? If a component is removed from the object hierarchy, is there any way for that component to be notified it has been removed and perform necessary cleanup? Using the compRemoved event doesn’t seem to work.

1 answer

Staff November 7, 2015

There is no special component destructor concept, since in general, when number of components is huge it can cost time. It is supposed that a developer has to implement it if it is required. The way it can be implemented is catching component removed events. You should understand few things regarding this event:

  • when component “A” is removed from component B that means “compRemoved” will be called from B (may be more proper name for the event handler is kidRemoved).
  • one more way to control component removal is overriding “setParent(p)” method to check if the passed as argument parent is null.
  • In both cases described in previous points you will not get any removal events for children components of the removed component. For instance if component “A” has been removed and the component “A” has number of children components no removal events are expected to be fired for the children components.

Now, if you need more general solution, that can catch all components removal events you should register global component listener and implement recursive traveling over removed components hierarchy (if necessary). Something like the following:

...
zebra.ui.events.addListener({
compRemoved : function (parent, index, kid) {
// implement "kid" component destruction here
// if you need you can go trough kid hierarchy
// to perform destruction procedure over its kids and so on
...
}
});
#1

Please login or Register to Submit Answer