We have updated Flexmonster Software License Agreement, effective as of September 30, 2024. Learn more about what’s changed.

Is there a way to add and remove event callbacks that have parameters?

Answered
Michael T asked on June 13, 2022

trying to add / remove a callback to an event (e.g. afterchartrender) when there are parameters. 
is there a way to do it? 
 
i'm able to add a parameterized function as a callback using an anonymous function wrapper, but don't know how to use .off to remove that specific callback after.
is there a way? e.g. using .bind?
 
related, is there a way to get a list of all callbacks bound to a particular event?
 
thank you,
 

3 answers

Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster June 15, 2022

Hello, Michael!
 
Thank you for contacting us.
 
Kindly note that you can remove the specific callback by passing the function name to the off() API call as follows:

const customCallbackHandler = (...) => {...};
flexmonster.off("afterchartdraw", customCallbackHandler);

 
Currently, Flexmonster does not provide a way to get a list of all callbacks bound to a particular event. However, it is possible to remove all callbacks of the event. This can be done by calling off() without the second parameter:

flexmonster.off("afterchartdraw")

Here is a JSFiddle example for reference: https://jsfiddle.net/flexmonster/tygxsg5d/.

For more information, please look through our docs: https://www.flexmonster.com/api/off/.
 
We hope it helps. Feel free to contact us if any further questions arise.
 
Regards,
Solomiia

Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster June 22, 2022

Hello, Michael!

Hope you are doing well.

Our team is wondering if you had a chance to try the suggested approach of removing a specific callback. Could you please let us know if it helps?

Looking forward to hearing from you.

Regards,
Solomiia

Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster June 29, 2022

Hello, Michael!

Hope you are having a great week.

Just checking in to ask if the suggested approach was helpful.

Looking forward to your response.

Regards,
Solomiia

Please login or Register to Submit Answer