Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List input should accept any type #376

Open
Lutymane opened this issue Mar 15, 2022 · 2 comments
Open

List input should accept any type #376

Lutymane opened this issue Mar 15, 2022 · 2 comments

Comments

@Lutymane
Copy link

Lutymane commented Mar 15, 2022

Hi, I tried to make a list input with function values and it failed with Error: No matching controller for 'op'.

Current workaround is setting initial value to 0 (but basically any number or string), as the type is checked only upon creation and it just works perfectly afterwards.

So the issue is there seem to be no reason to limit lists to only numbers and strings and do any type checking.

Min repro:

const sum = (a, b) => (a + b);
const sub = (a, b) => (a - b);

let params = {
    op: sum,
};
const pane = new Pane();
pane.addInput(params, "op", {
  label: "operation",
  options: {
    sum,
    sub,
  }
});
@alijaya
Copy link

alijaya commented Sep 2, 2022

But if it's function, it could not be serialized right?
It will cause headache to serialize that... I think it's better to do it with enum, and select the appropriate function from it.

@Lutymane
Copy link
Author

Lutymane commented Sep 2, 2022

Technically, function can be serialized by storing the code as string Function.toString() and then parsed back with eval.

But I don't think the functions should be serialized at all and just be skipped like in JSON

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants