UNPKG

proxyequal

Version:

A proxy based usage tracking and comparison

49 lines (46 loc) 1.63 kB
var _collectionHandlers; // Based on https://github.com/nx-js/observer-util/blob/master/src/builtIns/index.js // built-in object can not be wrapped by Proxies, or, to be clear - unfreezed // their methods expect the object instance as the 'this' instead of the Proxy wrapper // complex objects are wrapped with a Proxy of instrumented methods // which switch the proxy to the raw object and to add reactive wiring var collectionHandlers = (_collectionHandlers = { get: true, has: true, forEach: true, keys: true, values: true, entries: true, size: true }, _collectionHandlers[Symbol.iterator] = true, _collectionHandlers); var handlers = { Map: collectionHandlers, Set: collectionHandlers, WeakMap: collectionHandlers, WeakSet: collectionHandlers, Object: false, Array: false, Int8Array: false, Uint8Array: false, Uint8ClampedArray: false, Int16Array: false, Uint16Array: false, Int32Array: false, Uint32Array: false, Float32Array: false, Float64Array: false }; var globalObj = typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : {}; export function shouldInstrument(_ref) { var constructor = _ref.constructor; if (!constructor) { return true; } var name = constructor.name; var isBuiltIn = typeof constructor === 'function' && name in globalObj && globalObj[name] === constructor; return !isBuiltIn || handlers.hasOwnProperty(name); } export var getCollectionHandlers = function getCollectionHandlers(_ref2) { var constructor = _ref2.constructor; return constructor && handlers[constructor.name]; };