Skip to content

Commit

Permalink
Support a destroy method in layers
Browse files Browse the repository at this point in the history
FEATURE: Layers can now provide a `destroy` function to be called when
the layer is removed.

Issue codemirror/dev#989
  • Loading branch information
marijnh committed Nov 30, 2022
1 parent 494c5f3 commit 69c0025
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/layer.ts
Expand Up @@ -201,6 +201,9 @@ interface LayerConfig {
markers(view: EditorView): readonly LayerMarker[]
/// If given, this is called when the layer is created.
mount?(layer: HTMLElement, view: EditorView): void
/// If given, called when the layer is removed from the editor or
/// the entire editor is destroyed.
destroy?(layer: HTMLElement, view: EditorView): void
}

function sameMarker(a: LayerMarker, b: LayerMarker) {
Expand Down Expand Up @@ -263,6 +266,7 @@ class LayerView {
}

destroy() {
if (this.layer.destroy) this.layer.destroy(this.dom, this.view)
this.dom.remove()
}
}
Expand Down

0 comments on commit 69c0025

Please sign in to comment.