Skip to content

Custom handling when the block is disposed #6319

@e-gloo

Description

@e-gloo

Is your feature request related to a problem? Please describe.

If I understood correctly (and has it is in the code), we cannot yet make a variable referenced by a field other than a FieldVariable. I needed a way to make 2 fields, a text field and a dropdown field, being linked somehow, so whenever we change the value in the text field, it is updated in the dropdown field at the same time, mainly when the value selected is the same as the value from the text field. In order to achieve this, when the block of the text field is created, it creates a variable with the same id as the block id, and the same name as the text field value. Then, when the value of the text field is updated, it renames the appropriate variable with the new value. From there, the block of the dropdown field listen when the variable is renamed, and then update the current value if needed.
Everything works just fine, except the block of the text field is disposed. As the block does not get the "delete" event of himself, it can't delete the related variable, and the value will never be updated in the dropdown field.

Describe the solution you'd like

There's already init function at the block definition, maybe we could have destroy function which would be called when the block is disposed, then we would have the same principle has a constructor/destructor.

Describe alternatives you've considered

Other ideas:

  • Create a new type of extension that would be called when the block is disposed instead of when the block is created.
  • Dispose the block after the onchange function is called which would let the current block get the event of it's deletion.

Additional context

Note that this is pretty much a workaround a field not being able to reference a variable. It would be better to get this feature as the variable's name would depend on the text field value, and calling refreshVariableName would update the dropdown field value. However, we would still need a way to delete the variable when the block of the text field is disposed.

Any other workarounds or ideas to handle this. The only thing I want to avoid if possible, is to handle this in the workspace change listener, as I would need to handle every disposed block in there.

Thank you.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions