Skip to content

Commit

Permalink
Faster checks for non-observable types
Browse files Browse the repository at this point in the history
  • Loading branch information
ravijayaramappa committed Dec 17, 2018
1 parent 7d515ee commit 826cbd8
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/reactive-membrane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,23 @@ function defaultValueIsObservable(value: any): boolean {
if (value == null) {
return false;
}
if (isArray(value)) {
return true;
}

const proto = getPrototypeOf(value);
return (proto === ObjectDotPrototype || proto === null || getPrototypeOf(proto) === null);
switch (typeof value) {
// Quicker decisions for non-observable types. All possible values of typeof https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#Description
case 'boolean':
case 'number':
case 'string':
case 'symbol':
case 'function':
return false;
default:
if (isArray(value)) {
return true;
}

const proto = getPrototypeOf(value);
return (proto === ObjectDotPrototype || proto === null || getPrototypeOf(proto) === null);
}
}

const defaultValueObserved: ReactiveMembraneAccessCallback = (obj: any, key: PropertyKey) => {
Expand Down

0 comments on commit 826cbd8

Please sign in to comment.