Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce editor.transaction() to replace without* functions #2658

Closed
brendancarney opened this issue Mar 21, 2019 · 4 comments
Closed

Introduce editor.transaction() to replace without* functions #2658

brendancarney opened this issue Mar 21, 2019 · 4 comments

Comments

@brendancarney
Copy link
Collaborator

Introduce editor.transaction()

The withoutSaving, withoutNormalizing, an withoutMerging function behave in similar ways, creating a scope where saving and normalizing don't occur. withoutNormalizing is a little misleading, because it does normalize, it's just deferred until the end. I think these can be expressed with a single concept, editor.transaction(). A transaction is a concept that will be familiar to other programmers as an explicit way to group a set of changes. It's best explained by examples:

Basic Use (withoutNormalization)

editor.transaction(() => {
  editor.insertText("Hello")
  editor.insertText("World")
})

This is equivalent to the current withoutNormalizing. It defers normalization until the end, and groups everything inside into one save point.

withoutSaving

editor.transaction(() => {
  editor.insertText("Hello")
  editor.insertText("World")
}, { save: false })

Adding { save: false } will skip adding a save point to the editor.

withoutMerging

editor.transaction(() => {
  editor.insertText("Hello")
  editor.save()
  editor.insertText("World")
})

To accomplish withoutMerging, you would instead manually specify save points. Everything up until that point would be grouped into a save point.

More control over normalization.

Normalize when you want to:

editor.transaction(() => {
  editor.insertText("Hello")
  editor.normalize() // normalizes only dirty paths.
  editor.insertText("World")
})

Or don't at all:

editor.transaction(() => {
  editor.insertText("Hello")
  editor.normalize() // normalizes only dirty paths.
  editor.insertText("World")
}, { normalize: false })

Main benefits

  • A simpler, smaller API, eliminating a few confusing functions
  • More low level control over when things like saving and normalization happen. This could provide a solid workaround for a lot of performance issues in slate relating to normalizations.
  • Can be added as a non-breaking change to start
@cameracker
Copy link
Collaborator

Sounds good and I think this would meet all of my requirements for this feature.

@brendancarney
Copy link
Collaborator Author

Another benefit: I often find myself using these without* functions together. This is a very small pro, but still a pro. I'd rather write:

editor.transaction(() => {
  // do stuff
}, { save: false })

than

editor.withoutNormalization(() => {
  editor.withoutSaving(() => {
    // do stuff
  })
})

@mauricedoepke
Copy link

@ianstormtaylor @brendancarney

I am still pretty new to slate.
But it seems to me like in the most recent version Editor.withoutNormalizing pretty much does what is suggested here and the withoutSaving and withoutMerging functions seem to not exist anymore.

So this seems kind of solved to me and can probabbly be closed?

@dylans
Copy link
Collaborator

dylans commented Sep 2, 2021

@ianstormtaylor @brendancarney

I am still pretty new to slate.
But it seems to me like in the most recent version Editor.withoutNormalizing pretty much does what is suggested here and the withoutSaving and withoutMerging functions seem to not exist anymore.

So this seems kind of solved to me and can probabbly be closed?

I agree that withoutNormalizing has effectively become what was proposed, so I'm closing this. Thanks!

@dylans dylans closed this as completed Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants