rxjs-zone-less
Version:
A set of wrappers for RxJS to avoid unnecessary change detection and zone interference in Angular.
28 lines (27 loc) • 1.4 kB
JavaScript
var __globalThis = typeof globalThis !== 'undefined' && globalThis;
var __window = typeof window !== 'undefined' && window;
var __self = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' &&
self instanceof WorkerGlobalScope && self;
var __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.
var _global = __globalThis || __global || __window || __self;
export var Promise = getZoneUnPatchedApi('Promise');
export function setInterval(cb, ms) {
if (ms === void 0) { 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];
}