Skip to content

Commit f38c344

Browse files
AndrewKushnirthePunderWoman
authored andcommitted
refactor(core): make platform core providers tree-shakable (angular#45506)
This commit refactors the set of hardcoded platform core providers into tree-shakable providers. In addition to making them tree-shakable, this would also avoid the need to rely on the platform creation logic in an upcoming bootstrap logic for Standalone Components. PR Close angular#45506
1 parent 3c1695e commit f38c344

File tree

8 files changed

+10
-26
lines changed

8 files changed

+10
-26
lines changed

packages/core/src/application_ref.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export interface BootstrapOptions {
281281
*
282282
* @publicApi
283283
*/
284-
@Injectable()
284+
@Injectable({providedIn: 'platform'})
285285
export class PlatformRef {
286286
private _modules: NgModuleRef<any>[] = [];
287287
private _destroyListeners: Function[] = [];

packages/core/src/application_tokens.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ export const PLATFORM_INITIALIZER = new InjectionToken<Array<() => void>>('Platf
5454
* A token that indicates an opaque platform ID.
5555
* @publicApi
5656
*/
57-
export const PLATFORM_ID = new InjectionToken<Object>('Platform ID');
57+
export const PLATFORM_ID = new InjectionToken<Object>('Platform ID', {
58+
providedIn: 'platform',
59+
factory: () => 'unknown', // set a default platform name, when none set explicitly
60+
});
5861

5962
/**
6063
* A [DI token](guide/glossary#di-token "DI token definition") that provides a set of callbacks to

packages/core/src/console.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {Injectable} from './di';
1010

11-
@Injectable()
11+
@Injectable({providedIn: 'platform'})
1212
export class Console {
1313
log(message: string): void {
1414
// tslint:disable-next-line:no-console

packages/core/src/platform_core_providers.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,12 @@
77
*/
88

99
import {createPlatformFactory, PlatformRef} from './application_ref';
10-
import {PLATFORM_ID} from './application_tokens';
11-
import {Console} from './console';
12-
import {Injector, StaticProvider} from './di';
13-
import {TestabilityRegistry} from './testability/testability';
14-
15-
const _CORE_PLATFORM_PROVIDERS: StaticProvider[] = [
16-
// Set a default platform name for platforms that don't set it explicitly.
17-
{provide: PLATFORM_ID, useValue: 'unknown'},
18-
{provide: PlatformRef, deps: [Injector]},
19-
{provide: TestabilityRegistry, deps: []},
20-
{provide: Console, deps: []},
21-
];
10+
import {StaticProvider} from './di';
2211

2312
/**
2413
* This platform has to be included in any other platform
2514
*
2615
* @publicApi
2716
*/
28-
export const platformCore = createPlatformFactory(null, 'core', _CORE_PLATFORM_PROVIDERS);
17+
export const platformCore: (extraProviders?: StaticProvider[]|undefined) => PlatformRef =
18+
createPlatformFactory(null, 'core', []);

packages/core/src/testability/testability.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export class Testability implements PublicTestability {
230230
* A global registry of {@link Testability} instances for specific elements.
231231
* @publicApi
232232
*/
233-
@Injectable()
233+
@Injectable({providedIn: 'platform'})
234234
export class TestabilityRegistry {
235235
/** @internal */
236236
_applications = new Map<any, Testability>();

packages/core/test/bundling/animations/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,6 @@
137137
{
138138
"name": "ConnectableSubscriber"
139139
},
140-
{
141-
"name": "Console"
142-
},
143140
{
144141
"name": "DASH_CASE_REGEXP"
145142
},

packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@
101101
{
102102
"name": "ConnectableSubscriber"
103103
},
104-
{
105-
"name": "Console"
106-
},
107104
{
108105
"name": "ControlContainer"
109106
},

packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@
107107
{
108108
"name": "ConnectableSubscriber"
109109
},
110-
{
111-
"name": "Console"
112-
},
113110
{
114111
"name": "ControlContainer"
115112
},

0 commit comments

Comments
 (0)