rxjs-zone-less
Version:
A set of wrappers for RxJS to avoid unnecessary change detection and zone interference in Angular.
27 lines (26 loc) • 1.38 kB
JavaScript
const __globalThis = typeof globalThis !== 'undefined' && globalThis;
const __window = typeof window !== 'undefined' && window;
const __self = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' &&
self instanceof WorkerGlobalScope && self;
const __global = typeof global !== 'undefined' && global;
// Always use __globalThis if available, which is the spec-defined global variable across all
// environments, then fallback to __global first, because in Node tests both __global and
// __window may be defined and _global should be __global in that case.
const _global = __globalThis || __global || __window || __self;
export const Promise = getZoneUnPatchedApi('Promise');
export function setInterval(cb, ms = 0) {
return getZoneUnPatchedApi('setInterval')(cb, ms);
}
export function clearInterval(id) {
return getZoneUnPatchedApi('clearInterval')(id);
}
export function getZoneUnPatchedApi(targetOrName, name) {
// If the user has provided the API name as the first argument, for instance:
// `const addEventListener = getZoneUnPatchedApi('addEventListener');`
// Then we just swap arguments and make `global` or `window` as the default target.
if (typeof targetOrName === 'string') {
name = targetOrName;
targetOrName = _global;
}
return targetOrName['__zone_symbol__' + name] || targetOrName[name];
}