Is there an API to monitor the return value of a function, rather than the value of an object property? This would add a lot of flexibility to what a tweakpane can be used to monitor.
Right now I’m using a workaround like this:
// Some function whose return value we want to monitor
function funcToMonitor() { return Math.random(); }
pane.addMonitor(
{ get value() { return funcToMonitor(); } },
'value',
{ interval: 500 },
);
but it would be nice if there were a more ergonomic API, for example just pane.addMonitor(funcToMonitor)
.
A “perfect” API in my book would allow monitoring the awaited return value of functions that return promises, as well.
I think it's better to handle them with helper functions outside the API. They are easy to understand, and can keep simplicity and maintainability.
// Wrapper style
function addFunctionMonitor(pane: Pane, fn: Function, opts: MonitorParams) {
return pane.addMonitor(
{get value() {return fn();}},
'value',
opts,
);
}
addFunctionMonitor(pane, fn, {interval: 500});
// Proxy style
function createProxy(fn: Function) {
return [
{get value() {return fn();}},
'value',
];
}
pane.addMonitor(
...createProxy(fn),
{interval: 500},
);
Owner Name | cocopon |
Repo Name | tweakpane |
Full Name | cocopon/tweakpane |
Language | TypeScript |
Created Date | 2016-05-10 |
Updated Date | 2023-03-17 |
Star Count | 2603 |
Watcher Count | 19 |
Fork Count | 71 |
Issue Count | 11 |
Issue Title | Created Date | Updated Date |
---|