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

Flag for programmatic vs UI changes #145

Closed
wernerstucky opened this issue Sep 17, 2022 · 5 comments
Closed

Flag for programmatic vs UI changes #145

wernerstucky opened this issue Sep 17, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@wernerstucky
Copy link
Contributor

Hi Jos
I'm a big fan of your original library, we used it to develop a collaborative JSON editor.

The key functionality we relied on was that setting the content programmatically didn't emit a onChange.
This prevented loops in the 2 editors updating each other. When we set the content a onChange didn't happen, when the human made a change we picked that up and transmitted to the other editor and did a programatic update.

Is there anyway to enhance the Svelte component to maybe pass a flag letting us know if it was a change from called the set() or update() functions or if the change was a result of a UI edit.

Regards

@cloydlau
Copy link
Contributor

I’d been struggling on this too while making json-editor-vue, I use two flags to solve this.

@wernerstucky
Copy link
Contributor Author

Thanks @cloydlau I'll go have a look at how you solved it

@josdejong josdejong added the enhancement New feature or request label Sep 19, 2022
@josdejong
Copy link
Owner

Thanks Werner, very good point.

For reference: the reason that I recently change the behavior from onChange events on user changes only to all changes was the discussion here #128.

I agree that the old behavior is also very handy to prevent infinite loops and needless callbacks. So both cases can be useful, and your idea to be able to distinguish programmatic vs user changes makes sense.

For the time being: you can indeed set some flag before doing a programmatic update, and reset it after the update, and in the onChange you can check for this flag. And alternatively, it may be possible to compare the updated content against the previous contents in onChange, and if there is no difference ignore the change.

@wernerstucky
Copy link
Contributor Author

Thanks Jos, I'll do the flag thing for now.

@josdejong
Copy link
Owner

In v0.22.0 we've changed the behavior of onChange to not trigger anymore for programmatic changes. This resolves this issue indirectly, no flag needed anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants