@zedux/core
Version:
A high-level, declarative, composable form of Redux
24 lines (23 loc) • 1.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.is = void 0;
/**
* is() - Checks if a value is an instance of a class
*
* We can't use instanceof 'cause that breaks across realms - e.g. when an atom
* instance is shared between a parent and child window, that instance's object
* reference will be different in both windows (since each window creates its
* own copy of Zedux).
*
* The classToCheck should have a static $$typeof property whose value is a
* symbol created with Symbol.for() (sharing the symbol reference across realms)
*
* This works no matter how deep the inheritance tree is for either object
* passed.
*
* @param val anything - the thing we're checking
* @param classToCheck a class with a static $$typeof property
* @returns boolean - whether val is an instanceof classToCheck
*/
const is = (val, classToCheck) => { var _a; return ((_a = val === null || val === void 0 ? void 0 : val.constructor) === null || _a === void 0 ? void 0 : _a.$$typeof) === classToCheck.$$typeof; };
exports.is = is;