retejs / rete

JavaScript framework for visual programming
https://retejs.org
MIT License
10.04k stars 652 forks source link

Odd issue with some controls in customize not having a payload. #694

Closed arthurwolf closed 7 months ago

arthurwolf commented 7 months ago

I'm working on having custom controls (i'll ultimately have a lot of them, custom inputs, custom outputs, and custom controls).

Just spent 3 hours tracking down a bug, and it came down to this: in the "customize" thingie:

 render.addPreset(
    Presets.classic.setup({
      customize: {
        control(data) {
          if (data.payload instanceof ButtonControl) {
            return CustomButton;
          }
          if (data.payload instanceof ProgressControl) {
            return CustomProgress;
          }
          if (data.payload instanceof ClassicPreset.InputControl) {
            return Presets.classic.Control;
          }
        }
      }
    })
  );

Some have a payload (most), but some do not (Inputs). So when you do the context.payload instanceof ClassicPreset.InputControl check, it'll be true for outputs but not for outputs...

What's going on here? Am I missing something? I've read the documentation a lot, and even some of the source code, and still have a hard time understanding what's going on.

Any help would be greatly appreciated.

Cheers.

(awesome project, started supporting on Patreon)

arthurwolf commented 7 months ago

Closing as I found a workaround (even if I still don't get what's going on), and I don't want to waste any help considering how many questions I have... Sorry for the noise.