react-magic-state
Version:
React state management without the hassle.
30 lines (29 loc) • 857 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const observableTypes = new WeakMap();
function canObserve(target) {
var _a;
if (target == null) {
return false;
}
const constructor = (_a = target) === null || _a === void 0 ? void 0 : _a.constructor;
if (observableTypes.has(constructor)) {
return observableTypes.get(constructor);
}
let result = false;
if (constructor === Object) {
result = true;
}
else if (constructor === Array) {
result = true;
}
else if (!isBuiltIn(constructor)) {
result = true;
}
observableTypes.set(constructor, result);
return result;
}
exports.canObserve = canObserve;
function isBuiltIn(constructor) {
return (constructor.toString().indexOf("[native code]") >= 0);
}