Our pure JavaScript Scheduler component


Post by derreck »

Hi,

We have some expensive resource traversals in our treeMenuToggle(). It's getting called for every visible element when expandAll() or collapseAll() is called.

Is there a way I can prevent that from happening? We only want treeMenuToggle() to emit on individual menu toggles.

Thanks for your time,
Derreck


Post by mats »

Can you please provide some more context? What's treeMenuToggle some code to look at would be helpful!


Post by derreck »

Sorry I meant that we have a expandnode & collapsenode listener that I do not want to execute on expandAll/collapseAll.

Is there a way I can prevent this? Maybe with something from the Event.source emitted on expandnode & collapsenode?


Post by derreck »

Or is there another way I can trigger an acton/function off a Tree toggle, without adding a listener for expandnode & collapsenode?


Post by mats »

You can simply detach your listener before calling expandAll/collapseAll? Or add a boolean flag which you can check in the expandnode / collapsenode listeners.

https://bryntum.com/docs/scheduler/#Core/mixin/Events#function-removeListener


Post by derreck »

In the Docs the removeListener takes in a 'config' object (not a string). What is that config model/object suppose to look like to remove a listener?

I don't see a property there to remove/disable, other than the once property.


Post by mats »

Just like with native DOM events you should use same params as when you subscribed.

const handler = () => {};
scheduler.on('foo', handler);
scheduler.un('foo', handler);

or use the 'detacher' function returned from the 'on' call:

Returns a detacher function unless configured with detachable: false. Call detacher to remove listeners


Post by derreck »

Scheduler.un and scheduler.removeListener take in an 'config' object not a string for me. Is there maybe a type issue?

Also, detachListeners ('expandnode') is not working either and what is the detacher function suppose to look like/do? Can't find it in the docs.


Post by mats »

Yes, slight docs issue. Now fixed!

here's how to use detacher:

const detacher = scheduler.on({
     someEvent : () => {} 
 });

// later
detacher();

Post Reply