question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Operations show the source of the change

See original GitHub issue

Problem 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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
juliankrispelcommented, Apr 10, 2021

@chasefarmer2808 you can already do this by overriding the apply method of slate.js, see related docs. Here’s an example

const withMetaData = editor => {
  const { apply } = editor

  editor.apply = op => {
    apply({
      ...op,
      myUserId,
    })
  }

  return editor
}
0reactions
dylanscommented, Jul 21, 2021

The example overriding apply is nice, but doesn’t cover calling a transform directly iiuc, e.g. Transforms.setNodes?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved What are sources of changes to your | Chegg.com
Question: What are sources of changes to your organization? Can you give an example that you faced as a source to change in...
Read more >
Change the source name of Discovery results
Open a list for the Configuration Item [cmdb_ci] table and filter on a discovery source field value you want to change. Use the...
Read more >
Detect and troubleshoot frequent configuration changes
Discusses how to detect and troubleshoot frequent configuration changes in System Center Operations Manager.
Read more >
Guide 6: Basic Business Operations for the Entrepreneur - Citi
A major theme throughout this series of guides is making the right decisions for your business. This guide provides information and many of...
Read more >
Manage Git branches | IntelliJ IDEA Documentation - JetBrains
In IntelliJ IDEA, all operations with branches are performed in the ... The Changes tool window that opens shows a list of all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found