Skip to content

Commit 36ae560

Browse files
JeanMecheatscott
authored andcommitted
refactor(core): remove the phase prop from AfterRenderOptions (angular#60641)
The `AfterRenderPhase` enum now becomes private, it isn't exported anymore. PR Close angular#60641
1 parent 9f31947 commit 36ae560

File tree

5 files changed

+4
-139
lines changed

5 files changed

+4
-139
lines changed

goldens/public-api/core/index.api.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,6 @@ export function afterRenderEffect<E = never, W = never, M = never>(spec: {
6262
export interface AfterRenderOptions {
6363
injector?: Injector;
6464
manualCleanup?: boolean;
65-
// @deprecated
66-
phase?: AfterRenderPhase;
67-
}
68-
69-
// @public @deprecated
70-
export enum AfterRenderPhase {
71-
EarlyRead = 0,
72-
MixedReadWrite = 2,
73-
Read = 3,
74-
Write = 1
7565
}
7666

7767
// @public

packages/core/src/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export {
104104
} from './render3/ng_module_ref';
105105
export {createComponent, reflectComponentType, ComponentMirror} from './render3/component';
106106
export {isStandalone} from './render3/def_getters';
107-
export {AfterRenderPhase, AfterRenderRef} from './render3/after_render/api';
107+
export {AfterRenderRef} from './render3/after_render/api';
108108
export {publishExternalGlobalUtil as ɵpublishExternalGlobalUtil} from './render3/util/global_utils';
109109
export {
110110
AfterRenderOptions,

packages/core/src/render3/after_render/api.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@
2323
* so, Angular is better able to minimize the performance degradation associated with
2424
* manual DOM access, ensuring the best experience for the end users of your application
2525
* or library.
26-
*
27-
* @deprecated Specify the phase for your callback to run in by passing a spec-object as the first
28-
* parameter to `afterRender` or `afterNextRender` instead of a function.
2926
*/
30-
export enum AfterRenderPhase {
27+
export const enum AfterRenderPhase {
3128
/**
3229
* Use `AfterRenderPhase.EarlyRead` for callbacks that only need to **read** from the
3330
* DOM before a subsequent `AfterRenderPhase.Write` callback, for example to perform

packages/core/src/render3/after_render/hooks.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,6 @@ export interface AfterRenderOptions {
5252
* with the current `DestroyRef`.
5353
*/
5454
manualCleanup?: boolean;
55-
56-
/**
57-
* The phase the callback should be invoked in.
58-
*
59-
* <div class="docs-alert docs-alert-critical">
60-
*
61-
* Defaults to `AfterRenderPhase.MixedReadWrite`. You should choose a more specific
62-
* phase instead. See `AfterRenderPhase` for more information.
63-
*
64-
* </div>
65-
*
66-
* @deprecated Specify the phase for your callback to run in by passing a spec-object as the first
67-
* parameter to `afterRender` or `afterNextRender` instead of a function.
68-
*/
69-
phase?: AfterRenderPhase;
7055
}
7156

7257
/**
@@ -419,12 +404,9 @@ function getHooks(
419404
mixedReadWrite?: (r?: unknown) => unknown;
420405
read?: (r?: unknown) => void;
421406
},
422-
phase: AfterRenderPhase,
423407
): AfterRenderHooks {
424408
if (callbackOrSpec instanceof Function) {
425-
const hooks: AfterRenderHooks = [undefined, undefined, undefined, undefined];
426-
hooks[phase] = callbackOrSpec;
427-
return hooks;
409+
return [undefined, undefined, /* MixedReadWrite */ callbackOrSpec, undefined];
428410
} else {
429411
return [
430412
callbackOrSpec.earlyRead,
@@ -458,12 +440,11 @@ function afterRenderImpl(
458440

459441
const tracing = injector.get(TracingService, null, {optional: true});
460442

461-
const hooks = options?.phase ?? AfterRenderPhase.MixedReadWrite;
462443
const destroyRef = options?.manualCleanup !== true ? injector.get(DestroyRef) : null;
463444
const viewContext = injector.get(ViewContext, null, {optional: true});
464445
const sequence = new AfterRenderSequence(
465446
manager.impl,
466-
getHooks(callbackOrSpec, hooks),
447+
getHooks(callbackOrSpec),
467448
viewContext?.view,
468449
once,
469450
destroyRef,

packages/core/test/acceptance/after_render_hook_spec.ts

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import {PLATFORM_BROWSER_ID, PLATFORM_SERVER_ID} from '@angular/common/src/platform_id';
1010
import {
11-
AfterRenderPhase,
1211
AfterRenderRef,
1312
ApplicationRef,
1413
ChangeDetectionStrategy,
@@ -458,108 +457,6 @@ describe('after render hooks', () => {
458457
]);
459458
});
460459

461-
it('should run callbacks in the correct phase and order when using deprecated phase flag', () => {
462-
const log: string[] = [];
463-
464-
@Component({
465-
selector: 'root',
466-
template: `<comp-a></comp-a><comp-b></comp-b>`,
467-
standalone: false,
468-
})
469-
class Root {}
470-
471-
@Component({
472-
selector: 'comp-a',
473-
standalone: false,
474-
})
475-
class CompA {
476-
constructor() {
477-
afterRender(
478-
() => {
479-
log.push('early-read-1');
480-
},
481-
{phase: AfterRenderPhase.EarlyRead},
482-
);
483-
484-
afterRender(
485-
() => {
486-
log.push('write-1');
487-
},
488-
{phase: AfterRenderPhase.Write},
489-
);
490-
491-
afterRender(
492-
() => {
493-
log.push('mixed-read-write-1');
494-
},
495-
{phase: AfterRenderPhase.MixedReadWrite},
496-
);
497-
498-
afterRender(
499-
() => {
500-
log.push('read-1');
501-
},
502-
{phase: AfterRenderPhase.Read},
503-
);
504-
}
505-
}
506-
507-
@Component({
508-
selector: 'comp-b',
509-
standalone: false,
510-
})
511-
class CompB {
512-
constructor() {
513-
afterRender(
514-
() => {
515-
log.push('read-2');
516-
},
517-
{phase: AfterRenderPhase.Read},
518-
);
519-
520-
afterRender(
521-
() => {
522-
log.push('mixed-read-write-2');
523-
},
524-
{phase: AfterRenderPhase.MixedReadWrite},
525-
);
526-
527-
afterRender(
528-
() => {
529-
log.push('write-2');
530-
},
531-
{phase: AfterRenderPhase.Write},
532-
);
533-
534-
afterRender(
535-
() => {
536-
log.push('early-read-2');
537-
},
538-
{phase: AfterRenderPhase.EarlyRead},
539-
);
540-
}
541-
}
542-
543-
TestBed.configureTestingModule({
544-
declarations: [Root, CompA, CompB],
545-
...COMMON_CONFIGURATION,
546-
});
547-
createAndAttachComponent(Root);
548-
549-
expect(log).toEqual([]);
550-
TestBed.inject(ApplicationRef).tick();
551-
expect(log).toEqual([
552-
'early-read-1',
553-
'early-read-2',
554-
'write-1',
555-
'write-2',
556-
'mixed-read-write-1',
557-
'mixed-read-write-2',
558-
'read-1',
559-
'read-2',
560-
]);
561-
});
562-
563460
it('should schedule callbacks for multiple phases at once', () => {
564461
const log: string[] = [];
565462

0 commit comments

Comments
 (0)