-
Notifications
You must be signed in to change notification settings - Fork 114
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
onChange not called when .patch() applies JSON patches #128
Comments
A reproduction is available here: https://codesandbox.io/s/svelte-jsoneditor-react-forked-u6r5w1?file=/src/SvelteJSONEditor.js |
Thanks Ryan! Sorry for the confusion. The idea is indeed that the Reason is that if I'll at least clarify this in the docs with the current behavior. |
I appreciate the clarification! It makes sense and I can manually handle the onChange and and patch in parallel myself, thanks! |
A quick follow-up to this question, would there be any interest in exposing an edit: A more detailed background of my use case: I have a large JSON configuration and a form that submits this configuration if there are changes. I have a set of different types of patches that can be made to the object, initiated by the user (previously done manually.) It's an awesome feature to be able to patch, but now not possible for me to react to diffs from the from through onChange. |
Yes, good questions. There is an function handleChange(updatedContent, previousContent, { contentErrors, patchResult }) {
console.log('onChange: ', { updatedContent, previousContent, contentErrors, patchResult })
} (on a side note: the exact function signature of the |
What I'm hoping to do is have my external UI care only about the output of a single callback, to determine whether valid changes have been made in the editor, whether by a user or programmatically via patch. If a user makes a change and it's valid, I'd like to know about that. If a patch is applied and results in a valid change, I'd like to know about that. So far I can't find a way forward with the currently exposed API. The |
I guess you can create a callback |
In my testing, The goal My efforts so far have been:
|
Thanks for your inputs. Two thoughts:
Please think along if you have more ideas 😄 |
I love both of those approaches! My hunch is that #2 should be possible and is preferred for a few reasons:
Another alternative comes to mind: consider a library like React Hook Form (RHF) as an interesting analogy. Mostly my external code wants to know the results of all the hard work JSONEditor has done, and react to those results without meddling too much in the internals. |
(And of course thanks for your time and collaboration!) |
Yes agree, it will make life easier if
You're welcome :) |
OK I've changed the behavior to always fire It was quite funny. I realized that this "round-trip" that I was concerned about is already happening all the time: every time a user does make a change 😂. And well, there is no performance problem with that at all and no loops. So, no problem to add this "round-trip" too when making a programmatic change. This change actually simplified the code for |
Changes are now published in |
That's great to hear! Can't wait to pull em down and try them out. Thanks for taking the time and glad there were some surprise benefits! |
I've just published a breaking |
Hi there! First off, thanks for two excellent libraries that have been incredibly useful!
It was my expectation that calling the
.patch
method would result in a call to theonChange
callback, but that doesn't seem to be the case in my setup. Is that the expected result? It's worth noting that it does trigger validation.Hoping to narrow down whether that's working as intended or due to my local setup.
(I'll do some work for a minimal repro)
The text was updated successfully, but these errors were encountered: