Listenting for modification events of a RealTimeArray


I am trying to use Convergence for the SlateJS rich text editor and am having trouble seeing change events in my RealTimeElement.

Here is a basic example of the data I would like to store in Convergence:

Each item in the root list is a node in the editor. If a remote user were to make a change to the “hello” text in the first item, I need to handle this event and update my editor state appropriately. Here’s what I tried so far:

Let doc be a variable of type RealTimeArray that contains the above data. Also let doc be contained in a RealTimeModel under the key “content”. Finally, when a character is added to one of the text fields, I isolate it, cast it to a RealTimeString, and call insert passing the relative offset and added character.
I tried listening for any changes to doc by doing

doc.on(ModelChangedEvent.NAME, event => console.log(event))

But nothing is logging to the console. Next, I tried subscribing to events on doc with => console.log(event))

But still nothing is logged when I insert characters into the text field. Finally, I’ve tried to assign an event listener to each item in the root list, as I assume these are each RealTimeObjects, and listening for granular changes is apparently more efficient. But this also didn’t appear to be catching any of the insert events. What am I doing wrong?

Thanks in advanced!

I was able to see changes to elements within the array by casting them to RealTimeObjects first. Just having them as RealTimeElements was not good enough. Must be a Typescript thing I’m guessing. Also, I should mention I’m using Typescript hehe

1 Like

Hmm that is interesting. Glad you got it figured out.