Skip to content

Consolidate CustomJS implementations #13994

Open

Description

Currently all of the CustomJS models essentially re-implement everything, i.e. there are many repetitions of code like

  get names(): string[] {
    return keys(this.args)
  }

  get values(): unknown[] {
    return values(this.args)
  }

across all of the CustomJS models, as well as other methods like _make_func that some of the models implement but not all. Lastly the experience with actual CustomJS is more developed, being able to accept function definitions in addition to just snippets.

I propose that all the scattered code for handling CustomJS logic be consolidated into one place so that repetition can be reduced, and behaviors can be made consistent. It seems like these days that a mixin class might be a possibility, but a compositional approach also seems reasonable. Either way, the factored out component should be responsible for:

  • handling the processing of args
  • parsing and caching Function objects from code string property values
  • invoking cached functions in a consistent way
  • reporting errors in a consistent way

As part of this, documentation should be updated to indicate that all CustomJS models work in the exact same way. (cf. #10794)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions