Retrieving the object a component is bound to
Opened this issue · 3 comments
Would it be possible to make the _obj
property of components public? This property is especially useful in callbacks. Here is an example:
new ControlKit()
.addPanel()
.addSlider({ interval: 250, range: [50, 500] }, 'interval', 'range', {onChange: function() {
someObject.blink(this._obj.interval);
}});
As you can see, I'm using an anonymous object: { interval: 250, range: [50, 500] }
. The reason I'm doing this is because I cannot change the actual object (it's from an external library) and I need to call the blink
function anytime the slider's value changes.
Is there a better way to do this ?
Thanks again!
The initial idea was to only reference objects in controlkit. You introduce a new usecase, which obviously makes it necessary to access the object itself from the callback. This will be added with the next version
So you will have to stick to named objs atm, I usually have this scenario:
//global settings object (although most of the time just used in main)
var settings = {
color: [0,0,0,1],
motion: {
speed: 0.35,
intensity : 1,
randomChance : 0.125
},
pause : false
}
// in your case
var settings = {
blink : {
interval: 250,
range: [50,500]
}
}
new ControlKit()
.addSlider(settings.blink, 'interval', 'range', {onChange: function() {
someObject.blink(settings.blink.interval);
}
});
Grouping them all under a settings
object makes a lot of sense. This is what I'm going to do for now. However, having an easy access to the bound object and to the current component value would be nice.
Thanks a lot!