Skip to content

Commit

Permalink
Pass the view object to the dispatch option
Browse files Browse the repository at this point in the history
FEATURE: `EditorViewConfig.dispatch` is now passed the view object as a
second argument.
  • Loading branch information
marijnh committed May 17, 2023
1 parent 5be081e commit ae3f952
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/editorview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface EditorViewConfig extends EditorStateConfig {
/// is the way updates get routed to the view. Your implementation,
/// if provided, should probably call the view's [`update`
/// method](#view.EditorView.update).
dispatch?: (tr: Transaction) => void
dispatch?: (tr: Transaction, view: EditorView) => void
}

export const enum UpdateState {
Expand Down Expand Up @@ -107,7 +107,7 @@ export class EditorView {
/// composition there.
get compositionStarted() { return this.inputState.composing >= 0 }

private _dispatch: (tr: Transaction) => void
private _dispatch: (tr: Transaction, view: EditorView) => void

private _root: DocumentOrShadowRoot

Expand Down Expand Up @@ -212,8 +212,9 @@ export class EditorView {
dispatch(tr: Transaction): void
dispatch(...specs: TransactionSpec[]): void
dispatch(...input: (Transaction | TransactionSpec)[]) {
this._dispatch(input.length == 1 && input[0] instanceof Transaction ? input[0]
: this.state.update(...input as TransactionSpec[]))
let tr = input.length == 1 && input[0] instanceof Transaction ? input[0]
: this.state.update(...input as TransactionSpec[])
this._dispatch(tr, this)
}

/// Update the view for the given array of transactions. This will
Expand Down

0 comments on commit ae3f952

Please sign in to comment.