-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Allow for custom History actions #442
base: master
Are you sure you want to change the base?
Allow for custom History actions #442
Conversation
Thanks Dave. Can you explain a bit more about the use case behind this PR? If I understand you correctly you want to be able to change the content of the JSON document externally (programmatically), and want to log this as a change in the history (which the user can undo/redo)? It may be interesting to pick this up in v6, which has JSON-Patch support built-in already which maybe makes this solution superfluous? |
This followed from #438. When I implemented a new context menu action, I wanted to be able to undo it, but the built-in History actions weren't sufficient. This also allows multiple operations to be grouped into a single history item. Is History in v6 implemented as a chain of JSON-Patches? Does the v6 solution allow custom patches (as opposed to built-in patches) to be submitted to History? |
Ah, that makes sense. In that case, shouldn't we allow defining undo/redo in the context menus directly? Via two new options The history in v6 is indeed a list of JSON-Patches, and a patch can contain one or multiple actions/changes (like add, replace, move, remove), so there is complete freedom there. JSON Patch is quite brilliant: very simple yet completely flexible. |
The use case that I provided was just one example. I think a use case could exist which would want to be able to be able to keep track of changes in history, with those changes coming from outside of the plugins. I feel that keeping the History more flexible is advantageous. As an example, the new test makes changes without using a plugin: Yes, it seems that JSON Patch is ideal for use with JSONEditor. I haven't looked much into v6 yet, so you may have already done this, but here's something to consider. In my integration with JSONEditor, I have built a simple engine around the history actions for implementing my context menu plugins' actions:
This encapsulates the action setup in |
Please check out In v6, you can call a method The following example shows how you can keep two editors in sync with |
It seems we independently arrived at very similar solutions. When I find the time, I will upgrade my integration to v6 and see how it works. |
👍 |
Thinking aloud: it may still be a good idea to finish your implementation for |
Minor change to allow custom History actions to be recorded.
Includes a simple test, but no documentation (other than the
History.prototype.add
docblock).