ember-mobiledoc-editor
ember-mobiledoc-editor copied to clipboard
Use a stable key to guard against data loop
The data-loop defenses in the mobiledoc-editor component (_localMobiledoc
and _upstreamMobileDoc
) aren't sufficient to guard against many possible data loops, so it's easy to lose cursor position.
We could use an explicit document key/id instead. In practice, there is usually a good key laying around, like:
{{mobiledoc-editor mobiledoc=post.body key=post.id on-change=(action (mut post.body))}}
The above example would only rebuild the editor if key
changes. It would safely ignore any of its own changes that come back down.
I implemented this pattern in a component that wraps mobiledoc-editor and it seems to work well.