cocopon / tweakpane

:control_knobs: Compact GUI for fine-tuning parameters and monitoring value changes
https://tweakpane.github.io/docs/
MIT License
3.65k stars 90 forks source link

.on events have no 'this' defined #59

Closed ciknowles closed 4 years ago

ciknowles commented 4 years ago

I noticed when binding to an 'on' event that 'this' is undefined when the handler is called.

For example: tweakpane.addInput(menu, 'value', someconfig) .on('change', myfunction);

where myfunction(value) { //doing something here //but 'this' undefined unless you explicitly call 'bind' on the handler function }

Should 'this' be set to the input interface instance?

Chris

ciknowles commented 4 years ago

This isn't such a bad idea. It makes you explicitly force the context.

The only issue is that you need to keep references to the InputBindings after addInput calls if you wish to use them later.

Would you consider allowing bindings to be added with a 'key'. Then extending the API to include a getBinding(key) call?

addInput(menu, 'value', {key:'myid',....});

Later on I can then just call tweakpane.getBinding('myid');

Chris

cocopon commented 4 years ago

I don't have a plan to add key because it is not natural, but the first idea (binding handlers to appropriate APIs) looks good.

cocopon commented 4 years ago

Fixed in #69. Please wait for the next release.