UNPKG

rxjs-zone-less

Version:

A set of wrappers for RxJS to avoid unnecessary change detection and zone interference in Angular.

42 lines (41 loc) 1.94 kB
import { Subscription } from 'rxjs'; import { getZoneUnPatchedApi } from './zone-less'; var cancelAnimationFrame = getZoneUnPatchedApi('cancelAnimationFrame'); var requestAnimationFrame = getZoneUnPatchedApi('requestAnimationFrame'); export var animationFrameProvider = { // When accessing the delegate, use the variable rather than `this` so that // the functions can be called without being bound to the provider. schedule: function (callback) { var request = requestAnimationFrame; var cancel = cancelAnimationFrame; var delegate = animationFrameProvider.delegate; if (delegate) { request = delegate.requestAnimationFrame; cancel = delegate.cancelAnimationFrame; } var handle = request(function (timestamp) { // Clear the cancel function. The request has been fulfilled, so // attempting to cancel the request upon unsubscription would be // pointless. cancel = undefined; callback(timestamp); }); return new Subscription(function () { return cancel === null || cancel === void 0 ? void 0 : cancel(handle); }); }, requestAnimationFrame: function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var delegate = animationFrameProvider.delegate; return ((delegate === null || delegate === void 0 ? void 0 : delegate.requestAnimationFrame) || requestAnimationFrame).apply(void 0, args); }, cancelAnimationFrame: function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var delegate = animationFrameProvider.delegate; return ((delegate === null || delegate === void 0 ? void 0 : delegate.cancelAnimationFrame) || cancelAnimationFrame).apply(void 0, args); }, };