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

jsonpatch.generate modifies observed object #18

Closed
gabor-s opened this issue Aug 24, 2013 · 5 comments
Closed

jsonpatch.generate modifies observed object #18

gabor-s opened this issue Aug 24, 2013 · 5 comments

Comments

@gabor-s
Copy link

gabor-s commented Aug 24, 2013

Hi,

if I call jsonpatch.generate() the first time it generates the patches normally, but modifies the observed object, so the subsequent calls to jsonpatch.generate() don't generate any patches. Is it intentional, or is it a bug?

Regards
Gábor

@Starcounter-Jack
Copy link
Owner

Hi Gábor,

Do you have any sample code to illustrate the issue? The intended behaviour is to generate patches for changes that follows the previous call to jsonpatch.generate(). I.e. the following chain of events should be true:

  1. Create some objects
  2. Change said objects
  3. Observe said objects (for the first time)
  4. Change said objects again
  5. Call generate - only changes in step 4 should be generated in the patch
  6. Change said objects yet another time
  7. Call generate a second time - only changes in step 6 should be generated in the patch
  8. Call generate a third time - no changes should be generated in the patch (as there are no changes since last patch)

If this is not what you are experiencing, please let me know.

@gabor-s
Copy link
Author

gabor-s commented Sep 2, 2013

Hi,

if this is the intended behavior than no problem. I was not aware the fact that calling generate() resets the internal state.
In my use case the user fills out an HTML form and when she clicks the submit button I call jsonpatch.generate() to generate the patches and I send those patches to the backend. But the data can be invalid, so the user has to modify it, she clicks the submit button again and in this case I expect jsonpatch.generate() to return all the modifications.

@Starcounter-Jack
Copy link
Owner

I believe we can make flushing optional

@gabor-s
Copy link
Author

gabor-s commented Sep 2, 2013

That would be great!

@warpech
Copy link
Collaborator

warpech commented Nov 26, 2014

Fixed in 893e5f4 on master branch, soon to be released as version 0.5.0

@warpech warpech closed this as completed Nov 26, 2014
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

3 participants