-
Notifications
You must be signed in to change notification settings - Fork 219
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
Change the behavior in case of undefined
value
#107
Conversation
This commit only changes the test to the proposed solution to treating undefineds. I think that `jsonpatch.generate` should treat undefined exactly the same way it is treated in `json.stringify` and `jsonpatch.compare`. Every test should go the following path: var a = /*some object*/; observe(a); a.change = /*new value*/; var patches1 = generate(a); var b = (same object); var c = clone(b); b.change = /*new value*/ var patches2 = jsonpatch.compare(b, c); expect(patches1).toReallyEqual(/*expected patch*/); expect(patches1).toReallyEqual(patches2); toReallyEqual is a wrapper around Underscore isEqual, which knows the difference between undefined, null and unset values.
|
||
~~However, to play nicer with natural JavaScipt objects `jsonpatch` can be applied to an object that contains `undefined`, in such case we will use it as native `JSON.stringify` - we will treat them as non-existing nodes, and map to `null` for array elements.~~ | ||
Whenever a value is set to `undefined` in JS, JSON-Patch methods `generate` and `compare` will treat it similarly to how JavaScript method `JSON.stringify` treats them. See the test suite (in the `test/` subdirectory) or the [ECMAScript spec](http://www.ecma-international.org/ecma-262/6.0/index.html#sec-json.stringify) for details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd link JSON.stringify
to MDN or in exact spec and briefly describe what it does, like "treat as not specified"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Done
@tomalec, all your comments reviewed and applied. Anything more to add? |
LGTM |
Done, thanks for the review! |
This is a fix for issues #105, #90, #60, #32 and a part of #76 that describes a problem with undefined
all tests pass after this commit