Operations show the source of the change
See original GitHub issueProblem When any change occurs within the editor, there is no way to determine who or what made that change. Was it from the user? Programmatically though an API call? A peer user (collaboration)? It would be helpful to know this information when business logic is needed post-change. Auto save is an example that comes to mind. For auto save to work, I need to listen to changes on the editor, and only save a change when I know that I made the change. In a collaborative setting, this is impossible to do because there is no distinction between changes I have made and ones other users have made.
Solution
Create a base abstract Operation type and add a source attribute to it. Have all derived Operation types extend this abstract base type. Then, in the default implementation for Editor.apply
, set the value of this source attribute to a default, like “api” or “user”. QuillJS does something similar:
quill.on('text-change', function(delta, oldDelta, source) {
if (source == 'api') {
console.log("An API call triggered this change.");
} else if (source == 'user') {
console.log("A user action triggered this change.");
}
});
Alternatives Allow operation types to be extendable so a source field can be appended onto it. Perhaps through a plugin.
Context The main use cases I see this enabling is auto save and change tracking.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6
Top GitHub Comments
@chasefarmer2808 you can already do this by overriding the
apply
method of slate.js, see related docs. Here’s an exampleThe example overriding apply is nice, but doesn’t cover calling a transform directly iiuc, e.g.
Transforms.setNodes
?