Given a simple list, it seems more complicated than needed to set a default value and have Tweakpane invoke the on(change) event for first-time load.
const models_list = settingsPage.addBlade({
view: "list",
label: "MyList",
options: [
{ text: "Foo", value: "assets/foo.txt" },
{ text: "Bar", value: "assets/bar.txt" },
{ text: "Foobar", value: "assets/foobar.txt" },
{ text: "BarBar", value: "assets/barbar.txt" }
],
value: "assets/foo.txt", // Have to set something other than what we want to start with
}) as ListBladeApi<string>;
models_list
.on('change', async (ev) => {
await asset.load(ev.value);
});
models_list.value = "assets/foo.txt"; // This does nothing if we hadn't set it to a non-default value
Ideally, just setting the value in opts should invoke the handler for the first time post-creation. But this doesn't happen. Also, setting the value explicitly to the same value as specified in opts doesn't invoke the event, because nothing has "changed" (but it was never really set in application state!).
The workaround is to set a different value than what is default and then explicitly set it to default after creation, which seems convoluted.
I understand your perspective, but the change event is literally intended for detecting value changes. A behavior that doesn't align with its name could lead to confusion.
Given a simple list, it seems more complicated than needed to set a default value and have Tweakpane invoke the on(change) event for first-time load.
Ideally, just setting the
value
inopts
should invoke the handler for the first time post-creation. But this doesn't happen. Also, setting the value explicitly to the same value as specified inopts
doesn't invoke the event, because nothing has "changed" (but it was never really set in application state!).The workaround is to set a different value than what is default and then explicitly set it to default after creation, which seems convoluted.