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 Bugs/array.prototype.find in v1 master #188

Merged
merged 7 commits into from
Dec 7, 2017

Conversation

hthetiot
Copy link
Contributor

@hthetiot hthetiot commented Dec 7, 2017

  • Deprecate find() in favor of findValue()
  • Deprecate findLast() in favor of findLastValue()
  • Add console warning
  • Detect legacy usage and display warning
  • Add ES6 Array.prototype.find shim when missing
  • Add ES6 Array.prototype.find basic spec

screen shot 2017-12-07 at 8 48 36 am

@hthetiot hthetiot added the bug label Dec 7, 2017
@hthetiot hthetiot self-assigned this Dec 7, 2017
@hthetiot
Copy link
Contributor Author

hthetiot commented Dec 7, 2017

@cesine @yang Can you check that PR

npm i montagejs/collections#bugs/Array.prototype.find

@hthetiot hthetiot added this to the 5.0.x milestone Dec 7, 2017
@hthetiot
Copy link
Contributor Author

hthetiot commented Dec 7, 2017

Need to add Array.prototype.find when missing also i think.

@hthetiot
Copy link
Contributor Author

hthetiot commented Dec 7, 2017

#36

@hthetiot hthetiot requested a review from kriskowal December 7, 2017 06:48
Copy link
Member

@kriskowal kriskowal left a comment

Choose a reason for hiding this comment

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

Just comments. Leaving a stamp since I don’t expect to need to do another review.

deque.js Outdated
typeof console !== 'undefined' &&
typeof console.warn === 'function'
) {
console.warn('.find function is deprecated please use findValue instead.');
Copy link
Member

Choose a reason for hiding this comment

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

Should only leave this note once for the module’s lifetime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added deprecatedWarn in each file for now, with TODO remove in v6 notes

deque.js Outdated
) {
console.warn('.find function is deprecated please use findValue instead.');
}
return Deque.prototype.findValue.apply(this, arguments);
Copy link
Member

Choose a reason for hiding this comment

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

Bypassing dynamic dispatch is likely overkill here. If a derivative type overrides find, we should use it, but you’re right to ensure that you forward variadic args in case they extend the API. Consider…

this.find.apply(this, arguments);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in Array|Deque|SortedArray

shim-array.js Outdated
typeof console !== 'undefined' &&
typeof console.warn === 'function'
) {
console.warn('Overrided Array.prototype.' + key, "Saved into _" + key);
Copy link
Member

Choose a reason for hiding this comment

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

It might be worthwhile to make a warn function that isolates the concern of feature detecting console.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done via deprecatedWarn

shim-array.js Outdated
console.warn('Overrided Array.prototype.' + key, "Saved into _" + key);
}
define("_" + key, Object.getOwnPropertyDescriptor(Array.prototype, key).value);
}
Copy link
Member

Choose a reason for hiding this comment

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

…but in general I’m not sure what purpose is served by setting aside the punched property. I don’t think anyone can rely on overridden properties being set aside, and in the cases where you care, it will be clearer to do so manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done via ArrayFindPrototype

shim-array.js Outdated
@@ -131,8 +142,77 @@ define("deleteAll", function (value, equals) {
}
return count;
});
// https://tc39.github.io/ecma262/#sec-array.prototype.find
if (!Array.prototype.find) {
Copy link
Member

Choose a reason for hiding this comment

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

Indentation style is not consistent below. Consider unexpand -t 2 | expand -t 4.

Copy link
Contributor Author

@hthetiot hthetiot Dec 7, 2017

Choose a reason for hiding this comment

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

fixed (THX)

shim-array.js Outdated

define("find", function (value, equals) {
// 7. Return undefined.
return undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessarily explicit, since omitting return entirely does the job.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

shim-array.js Outdated
define("find", function (value, equals, index) {
if (
typeof arguments[0] === 'function'
&& this instanceof Array
Copy link
Member

Choose a reason for hiding this comment

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

Opinion: I prefer to hang all operators off the end of the prior line and align terms of equal precedence on the same column.

if (
   x &&
   y &&
   z
) {
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done (THX)

@hthetiot
Copy link
Contributor Author

hthetiot commented Dec 7, 2017

Thx @kriskowal for wonderful review.

@hthetiot hthetiot merged commit af032cf into master Dec 7, 2017
@hthetiot hthetiot deleted the bugs/Array.prototype.find branch July 11, 2018 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants