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

Change the behavior in case of undefined value #107

Merged
merged 9 commits into from
Jun 7, 2016

Conversation

warpech
Copy link
Collaborator

@warpech warpech commented Jun 3, 2016

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

warpech added 5 commits May 31, 2016 12:27
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.
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

~~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.
Copy link
Collaborator

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"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Done

@warpech
Copy link
Collaborator Author

warpech commented Jun 6, 2016

@tomalec, all your comments reviewed and applied. Anything more to add?

@tomalec
Copy link
Collaborator

tomalec commented Jun 7, 2016

LGTM

@warpech warpech merged commit e0dcec4 into master Jun 7, 2016
@warpech
Copy link
Collaborator Author

warpech commented Jun 7, 2016

Done, thanks for the review!

@warpech warpech deleted the feature/reimplement-undefined-105 branch June 7, 2016 08:30
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

Successfully merging this pull request may close these issues.

2 participants