-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
operations/invert should not rely on internal state #2123
Comments
I think there's a nice property of being able to invert an operation without needing the original I'd be down with making that more the case, by standardizing extra properties on the operations that can allow us to remove these "stateful" ones. For example, I think the only reason |
I agree, it's a nice property. Another option might be just to include those values in the JSON as well on perhaps a properties object as you suggest. Then the user can decide whether to store the more detailed version or the minimal one. At times it can be useful to have these properties in user-land as well I find. Maybe we should just aim to include an example which demonstrates versions with slate? So an example where there are a few version states (references to Change objects) between which you can switch (and which roll back or apply changes as needed). Then we can decide what we need to do to make an example like that functional. Ultimately, we'd probably want to somehow identify Change objects so we can refer to them as a rollback target and so we can create something like a version tree, with different branches (basically git-like) |
@bryanph that sounds good to me! I think the example should ideally use the lower-level |
We still need to be able to refer to groups of operations though, since that is what defines an actual delta to the user. Perhaps we can introduce a Delta model or something like that, which holds a group of operations and identifies it with some key? That way we can keep it away from the Change model and just make the Change object refer to the Delta model. This model could then also be responsible for inverting the group of operations and perhaps even identifying it as an abstract operation or command (in the spirit of #2066). |
That could be. But what if we made it simpler and just used immutable |
Ok so how would moving to a given version work? Assuming we have an array of arrays of operations. To use a git analogy, a version is basically a commit? And the operations define how we move to this commit from the previous one? |
Yup exactly. The index in the top-level list is the version, and you take all of the bottom-level lists from your current index to the index you want to be at. If it’s forward you apply them directly. If it’s backward you invert them first and then apply them. |
@ianstormtaylor great, hopefully I can find some time to work on this some time soon :). |
Hi, I am thinking about this solution:
Reason (sorry about some math denotation, I find it is hard for me to express some ideas without math): Suppose we have However, for any pair of documents processed by one or more operations, In short, we shall think an operation as exact arrow from one document to another document, rather than an abstract map between a set of documents to another set of documents. Therefore, we can create an operation like this:
Then we can have operation structure like:
Then during Note: for implementing this proposal, we may need to implement bundle operation first. |
Then we define operation in this way:
|
Do you want to request a feature or report a bug?
Feature/bug-ish
What's the current behavior?
The undo/redo stack makes use of the invert function here
slate/packages/slate/src/operations/invert.js
Line 22 in ecf4892
slate/packages/slate/src/models/operation.js
Lines 239 to 251 in ecf4892
As a result, reverting operations on the user-side requires custom code to invert the given operations after this internal state is gone (like after a refresh).
What's the expected behavior?
My suggestion is to make operation.invert() just be a function of the document state and the raw operation, not on any internal state so that the case of inverting an operation from within the editor and from outside the editor is the same. This allows you to instantiate the history stack with operations that have been synced to a server on refresh and would make implementing a "version" example quite straight forward.
The text was updated successfully, but these errors were encountered: