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

Fix empty objects not being declared #9

Conversation

fixe
Copy link
Contributor

@fixe fixe commented Apr 7, 2015

No description provided.

@@ -18,7 +18,7 @@ tests = [{
}, {
m: 'a'
, o: [{b: 1}]
, e: null
, e: {}
Copy link
Owner

Choose a reason for hiding this comment

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

Why an empty object? I think a null is more appropriate since you asked for a and that didn't match anything, just like in the second test case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a consequence. See notes below.

@fixe fixe force-pushed the bugfix/fix-empty-objects-not-being-declared branch from efae5a1 to 6b0e3ce Compare April 7, 2015 16:58
@fixe
Copy link
Contributor Author

fixe commented Apr 7, 2015

@nemtsov PR updated.

@fixe fixe force-pushed the bugfix/fix-empty-objects-not-being-declared branch from 6b0e3ce to 21eaf99 Compare April 7, 2015 17:43
@fixe
Copy link
Contributor Author

fixe commented Apr 12, 2015

ping @nemtsov

@nemtsov
Copy link
Owner

nemtsov commented Apr 15, 2015

Apologies for the delay; I haven't had much time to thoroughly review this last week.

There are two changes in this PR. The bug-fix ("if not array -> _properties" one) I completely agree with and am ready to merge and the "if plain object -> {}" one, which needs more work. So, if you extract the former into a separate PR, I'll merge it ASAP.

Regarding the latter, there are two issues I see with it:

  1. It's inconsistent with other test-cases
    • Why is mask({a: 3}, 'b') null and not {} if we're making mask({a: {b: 3}}, 'a/c'), {}?
    • Why is mask({a: [{b: 3}]}, 'a/c') null and not {a: []} or even worse {a: [{}]}(??) ?
    • Assuming function A() { this.a = 3; this.b = 4}; var a = new A(), why does: mask(a, 'b'); return {b: 4} but mask({a: a}, 'a/c'); returns null, while mask({a: a}, 'a/b'); returns {a: {b: 4}}?
  2. The implementation of object detection does not work for the following case:
  • mask({a: {constructor: 2}}, 'a/c') -> null

@fixe
Copy link
Contributor Author

fixe commented Apr 19, 2015

@nemtsov PR submitted here. I'll take a look at your points and get back to you.

@nemtsov
Copy link
Owner

nemtsov commented Apr 20, 2015

@fixe I merged your other PR. Thanks!

@fixe fixe force-pushed the bugfix/fix-empty-objects-not-being-declared branch from 21eaf99 to 9ae8130 Compare April 28, 2015 16:12
@nunofgs nunofgs force-pushed the bugfix/fix-empty-objects-not-being-declared branch 2 times, most recently from 20c2104 to a9ced1a Compare August 20, 2015 11:24
@nunofgs
Copy link
Contributor

nunofgs commented Aug 20, 2015

@nemtsov I added another commit to this PR.

I had to change the .travis.yml to use iojs instead of nodejs due to the added support of the assert.deepStrictEqual() (See nodejs/node#639).

This was done because assert.deepEqual({}, []) was considered valid when it's not really what we intended.

Also, in regard to your previous questions:

Why is mask({a: 3}, 'b') null and not {} if we're making mask({a: {b: 3}}, 'a/c'), {}?

Absolutely correct. Fixed by the latest commit.

Why is mask({a: [{b: 3}]}, 'a/c') null and not {a: []} or even worse {a: [{}]}(??) ?

In my opinion, {a: [{}]} is correct in that case. The user supplied an array with an object inside. That object simply did not have any matching masks and so we were left with an empty object.

Assuming function A() { this.a = 3; this.b = 4}; var a = new A(), why does: mask(a, 'b'); return {b: 4} but mask({a: a}, 'a/c'); returns null, while mask({a: a}, 'a/b'); returns {a: {b: 4}}

Fixed by the latest commit.

@ruimarinho ruimarinho force-pushed the bugfix/fix-empty-objects-not-being-declared branch from a9ced1a to 0ce14b6 Compare August 28, 2015 13:53
@fixe
Copy link
Contributor Author

fixe commented Oct 12, 2015

ping @nemtsov

@nemtsov
Copy link
Owner

nemtsov commented Oct 14, 2015

Totally lost track of this PR. Will review / merge or comment on it this week.

@promag
Copy link

promag commented Nov 27, 2015

ping @nemtsov

@nunofgs
Copy link
Contributor

nunofgs commented Apr 5, 2016

Needed this PR again today. Here's what I was doing:

const data = {
  user: {
    lastName: 'foo'
  }
};

mask(data, 'user(firstName)');

The above mask was returning {} when it should really be returning { user: {} }, which this PR correctly fixes.

@nemtsov any chance you could take a look at this?

@nemtsov
Copy link
Owner

nemtsov commented Apr 8, 2016

Just wanted to let you know that I haven't forgotten about this and want to merge it in. I'll respond with specific comments as soon as I have some time.

@ruimarinho
Copy link

@nemtsov any chance of merging this one?

@nemtsov nemtsov merged commit 0ce14b6 into nemtsov:master May 22, 2016
@nemtsov
Copy link
Owner

nemtsov commented May 22, 2016

Merged. Thank you for your contribution and patience.

@fixe fixe deleted the bugfix/fix-empty-objects-not-being-declared branch October 12, 2016 13:06
@fixe fixe restored the bugfix/fix-empty-objects-not-being-declared branch October 12, 2016 20:43
@ruimarinho ruimarinho deleted the bugfix/fix-empty-objects-not-being-declared branch October 20, 2016 10:56
@ruimarinho ruimarinho restored the bugfix/fix-empty-objects-not-being-declared branch October 20, 2016 15:58
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.

5 participants