Callbacks-Framework-SMP
A helper script for Spider Monkey Panel and foobar2000 which allows to easily attach and manage event listeners associated to SMP callbacks without wrapping or repeating code. A lifesaver.
Helper meant mostly for coders not for final users, although it may be easily included on any script (don't expect how to's by my side apart from these instructions).
The problem with current SMP callbacks
Complex scripts, like those with UI, usually have interactive items at multiple places which must be linked to a callback to perform actions at certain events. While SMP allows modularization using include(), callbacks must be placed within a main file since redefinition of the function simply overwrites the previous one. That clearly limits the ability to just mix modules and or add event listeners to non-final scripts.


Using this framework it would translate into this:

Features
- Adds event listeners to SMP callbacks.
- Removes event listeners on demand.
- Allows to find if an event listener is active.
- Mimics mozilla implementation.
- Implements SPM planned design.
- Bypasess common limitation of including files with existing callbacks, wrapping, etc.
Usage
Just add an event listener to an specific event/callback.
const listener = () => {console.log('Hello world!');}
addEventListener('on_mouse_lbtn_up', listener);
That's all. To remove it just do:
removeEventListener('on_mouse_lbtn_up', listener);
Multiple listeners can be attached to the same event:
addEventListener('on_mouse_lbtn_up', () => {console.log('1!');});
addEventListener('on_mouse_lbtn_up', () => {console.log('2!');});
addEventListener('on_mouse_lbtn_up', () => {console.log('3!');});
addEventListener('on_mouse_lbtn_up', () => {console.log('14!');});
Listener removal may be done using their UUID or function:
const listener = () => {console.log('Hello world!');}
const uuid = addEventListener('on_mouse_lbtn_up', listener);
removeEventListener('on_mouse_lbtn_up', null, uuid);
There are more usage examples on the 'examples' folder.
Installation
Since the framework only requires 1 file, i.e. the main one, you can simply include it along any other script where you usually need a callback.

Download latest release (or nightly releases) at github:
https://github.com/regorxxx/Callbacks-Framework-SMP