Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/like-selector.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export function isLikeSelector(selector) {
const prototype = Reflect.getPrototypeOf(selector)
return selector !== null
&& typeof selector === 'object'
&& Reflect.getPrototypeOf(selector) === Object.prototype
&& (prototype === Object.prototype || prototype === Array.prototype)
Copy link
Member

Choose a reason for hiding this comment

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

I think this could use Array.isArray(selector). Note that Reflect.ownKeys() on an array returns length which messes up the next condition.

&& Reflect.ownKeys(selector).length > 0;
}

Expand All @@ -18,7 +19,7 @@ export function selectComparable(lhs, selector, circular = new Set()) {
return lhs;
}

const comparable = {};
const comparable = Array.isArray(selector) : [] : {};
for (const [key, rhs] of Object.entries(selector)) {
if (isLikeSelector(rhs)) {
comparable[key] = selectComparable(Reflect.get(lhs, key), rhs, circular);
Expand Down