Skip to content

Commit

Permalink
feat: update isLikeSelector for Reflect.ownKeys().length
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-poetic committed Mar 13, 2023
1 parent 3ffa5c0 commit 05fa702
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/like-selector.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
export function isLikeSelector(selector) {
const prototype = Reflect.getPrototypeOf(selector);
return selector !== null
&& typeof selector === 'object'
&& (prototype === Object.prototype || prototype === Array.prototype)
&& Reflect.ownKeys(selector).length > 0;
const isArrayOrObject = selector !== null && typeof selector === 'object';

if (!isArrayOrObject) {
return false;
}

const isArray = Array.isArray(selector);
const minimumKeysRequired = isArray ? 1 : 0;

return Reflect.ownKeys(selector).length > minimumKeysRequired;
}

export const CIRCULAR_SELECTOR = new Error('Encountered a circular selector');
Expand Down

0 comments on commit 05fa702

Please sign in to comment.