@zedux/core
Version:
A high-level, declarative, composable form of Redux
20 lines (19 loc) • 959 B
JavaScript
/**
* 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
*/
export 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; };