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

applyPatch not using deep copy #44

Closed
callingmybluff opened this issue Apr 9, 2019 · 2 comments
Closed

applyPatch not using deep copy #44

callingmybluff opened this issue Apr 9, 2019 · 2 comments

Comments

@callingmybluff
Copy link

I've looked around, and found #38 to be the most similar. However, I am facing a problem in the save category although that version is live probably.

Bug of feature?

This is a bug, I believe.

Use case / Example

https://jsfiddle.net/Ismaeel/1ewxshdq/

  1. Use "Safe" to switch between the two versions of the text. It works as expected.
  2. Use "Risky" to switch between the two versions of the text, and it fails. versions[0] takes something from versions[1]

Expected vs. Current output

I would expect my patch not to be modified at all, but that is not the case for now.

chbrown added a commit that referenced this issue Apr 11, 2019
@chbrown
Copy link
Owner

chbrown commented Apr 11, 2019

Good point. Fixed as of v3.0.2.

FWIW, your example was kinda confusing. The jsfiddle was unnecessary, and only distracted from your technically valid (and useful!) bug report. You could have just written something like:

const value = {}
const numbers = []
applyPatch(value, [
  {op: 'add', path: '/numbers', value: numbers},
  {op: 'add', path: '/numbers/-', value: 9},
])
assert.ok(numbers.length == 0)

...which is pretty much how I wrote the unit test for the bugfix.

@callingmybluff
Copy link
Author

callingmybluff commented Apr 11, 2019

Wow!
I did make it a bit complex I see 😶

Thanks for the fix!

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

No branches or pull requests

2 participants