Hello, can someone point me in the right direction...
# javascript
h
Hello, can someone point me in the right direction on how to wrap the
onUpdate
callback here properly:
Copy code
<EditorProvider
  extensions={extensions}
  content={content}
  slotAfter={<EditorToolbar />}
  editorProps={editorProps}
  onUpdate={({ editor }) => {
      setValue(editor.getJSON())
  }}
>
I it tried with
Copy code
external interface Editor {
    val options: EditorOptions
    fun setOptions(options: EditorOptions)
    fun getJSON(): dynamic
}

external interface EditorOptions {
  [...]
  var onUpdate: (editor: Editor) -> Unit
}

// Inside my component then:
EditorProvider {
    extensions = props.extensions
    content = props.content
    onUpdate = { editor ->
        println(editor.getJSON())
    }
}
But I only get
getJSON() is not a function
. When I do
useCurrentEditor().getJSON()
from a child it works. For reference: https://github.com/ueberdosis/tiptap/discussions/4636 Edit: Thank you for rubber ducking after looking deeper into the source:
Copy code
this.emit('update', {
      editor: this,
      transaction,
    })
I got it:
Copy code
external interface EditorOptions {
  [...]
  var onUpdate: (updaate: EditorUpdate ) -> Unit
}

external interface EditorUpdate {
    var editor: dynamic
    var transaction: dynamic
}
EditorProvider {
    extensions = props.extensions
    content = props.content
    onUpdate = { update ->
        println(JSON.stringify(update.editor.getJSON()))
    }
}
a
@turansky ^^
t
Copy code
external interface EditorOptions {
  [...]
  var onUpdate: (options: UpdateOptions) -> Unit

  interface UpdateOptions {
      val editor: Editor
  }
}
h
Thank you for answering, I really didn't see that there was another object in between. I also saw it when I looked at the source code of TipTap. The anonymous/unnamed
{({({({({({({
stuff is why I have trouble parsing JS 😞
t
({ editor })
-
editor
field from first parameter of function
Also you can use Kotlin
debugger
constant to stop execution in lambda and check parameters if signature isn't transparent
👀 1