From 2bebaa99cfd59a01b18114cd0463d032ca2a3cae Mon Sep 17 00:00:00 2001 From: Andrew Kushnir Date: Tue, 15 Feb 2022 15:23:12 -0800 Subject: [PATCH] refactor(core): drop unused `SCHEDULER` provider (#45102) (#45222) The `SCHEDULER` provider was used previously when both ViewEngine and Ivy code was present. After some prior refactoring, all references to the `SCHEDULER` token were removed, but the token itself remains present in the `ApplicationModule`, which makes it non-tree-shakable. This commit removes the `SCHEDULER` token as unused. PR Close #45102 PR Close #45222 --- packages/core/src/application_module.ts | 23 ---------------------- packages/core/src/render3/component_ref.ts | 11 ----------- 2 files changed, 34 deletions(-) diff --git a/packages/core/src/application_module.ts b/packages/core/src/application_module.ts index ec6abbbb067..7bc53404961 100644 --- a/packages/core/src/application_module.ts +++ b/packages/core/src/application_module.ts @@ -17,7 +17,6 @@ import {DEFAULT_CURRENCY_CODE, LOCALE_ID} from './i18n/tokens'; import {ComponentFactoryResolver} from './linker'; import {Compiler} from './linker/compiler'; import {NgModule} from './metadata'; -import {SCHEDULER} from './render3/component_ref'; import {NgZone} from './zone'; declare const $localize: {locale?: string}; @@ -62,7 +61,6 @@ export const APPLICATION_MODULE_PROVIDERS: StaticProvider[] = [ useClass: ApplicationRef, deps: [NgZone, Injector, ErrorHandler, ComponentFactoryResolver, ApplicationInitStatus] }, - {provide: SCHEDULER, deps: [NgZone], useFactory: zoneSchedulerFactory}, { provide: ApplicationInitStatus, useClass: ApplicationInitStatus, @@ -78,27 +76,6 @@ export const APPLICATION_MODULE_PROVIDERS: StaticProvider[] = [ {provide: DEFAULT_CURRENCY_CODE, useValue: USD_CURRENCY_CODE}, ]; -/** - * Schedule work at next available slot. - * - * In Ivy this is just `requestAnimationFrame`. For compatibility reasons when bootstrapped - * using `platformRef.bootstrap` we need to use `NgZone.onStable` as the scheduling mechanism. - * This overrides the scheduling mechanism in Ivy to `NgZone.onStable`. - * - * @param ngZone NgZone to use for scheduling. - */ -export function zoneSchedulerFactory(ngZone: NgZone): (fn: () => void) => void { - let queue: (() => void)[] = []; - ngZone.onStable.subscribe(() => { - while (queue.length) { - queue.pop()!(); - } - }); - return function(fn: () => void) { - queue.push(fn); - }; -} - /** * Configures the root injector for an app with * providers of `@angular/core` dependencies that `ApplicationRef` needs diff --git a/packages/core/src/render3/component_ref.ts b/packages/core/src/render3/component_ref.ts index 131303d61ca..69540a69aee 100644 --- a/packages/core/src/render3/component_ref.ts +++ b/packages/core/src/render3/component_ref.ts @@ -7,7 +7,6 @@ */ import {ChangeDetectorRef as ViewEngine_ChangeDetectorRef} from '../change_detection/change_detector_ref'; -import {InjectionToken} from '../di/injection_token'; import {Injector} from '../di/injector'; import {InjectFlags} from '../di/interface/injector'; import {ProviderToken} from '../di/provider_token'; @@ -36,7 +35,6 @@ import {createElementNode, writeDirectClass} from './node_manipulation'; import {extractAttrsAndClassesFromSelector, stringifyCSSSelectorList} from './node_selector_matcher'; import {enterView, leaveView} from './state'; import {setUpAttributes} from './util/attrs_utils'; -import {defaultScheduler} from './util/misc_utils'; import {getTNode} from './util/view_utils'; import {RootViewRef, ViewRef} from './view_ref'; @@ -71,15 +69,6 @@ function getNamespace(elementName: string): string|null { return name === 'svg' ? SVG_NAMESPACE : (name === 'math' ? MATH_ML_NAMESPACE : null); } -/** - * A change detection scheduler token for {@link RootContext}. This token is the default value used - * for the default `RootContext` found in the {@link ROOT_CONTEXT} token. - */ -export const SCHEDULER = new InjectionToken<((fn: () => void) => void)>('SCHEDULER_TOKEN', { - providedIn: 'root', - factory: () => defaultScheduler, -}); - function createChainedInjector(rootViewInjector: Injector, moduleInjector: Injector): Injector { return { get: (token: ProviderToken, notFoundValue?: T, flags?: InjectFlags): T => {