Skip to content

Commit

Permalink
fixup! refactor(core): initial implementation of {#defer} block run…
Browse files Browse the repository at this point in the history
…time
  • Loading branch information
AndrewKushnir committed Aug 28, 2023
1 parent 211d7df commit d61ff74
Show file tree
Hide file tree
Showing 15 changed files with 307 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ MyApp.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "0.0.0-
<div>
{{message}}
{#defer}Deferred content{/defer}
<p>Content after defer block</p>
</div>
`, isInline: true });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyApp, decorators: [{
Expand All @@ -22,6 +23,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDE
<div>
{{message}}
{#defer}Deferred content{/defer}
<p>Content after defer block</p>
</div>
`,
}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Component} from '@angular/core';
<div>
{{message}}
{#defer}Deferred content{/defer}
<p>Content after defer block</p>
</div>
`,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ MyApp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
$r3$.ɵɵtemplate(2, MyApp_Defer_2_Template, 1, 0);
$r3$.ɵɵdefer(3, 2);
$r3$.ɵɵdeferOnIdle();
$r3$.ɵɵelementEnd();
$r3$.ɵɵelementStart(5, "p");
$r3$.ɵɵtext(6, "Content after defer block");
$r3$.ɵɵelementEnd()();
}
if (rf & 2) {
$r3$.ɵɵadvance(1);
Expand Down
4 changes: 4 additions & 0 deletions packages/compiler/src/render3/view/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,10 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver

this.createDeferTriggerInstructions(deferredIndex, triggers, false);
this.createDeferTriggerInstructions(deferredIndex, prefetchTriggers, true);

// Allocate an extra data slot right after a defer block slot to store
// instance-specific state of that defer block at runtime.
this.allocateDataSlot();
}

private createDeferredDepsFunction(name: string, deferred: t.DeferredBlock) {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/render3/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ export function assertDirectiveDef<T>(obj: any): asserts obj is DirectiveDef<T>
}
}

export function assertIndexInDeclRange(lView: LView, index: number) {
const tView = lView[1];
export function assertIndexInDeclRange(tView: TView, index: number) {
assertBetween(HEADER_OFFSET, tView.bindingStartIndex, index);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/render3/instructions/advance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import {assertGreaterThan} from '../../util/assert';
import {assertIndexInDeclRange} from '../assert';
import {executeCheckHooks, executeInitAndCheckHooks} from '../hooks';
import {FLAGS, InitPhaseState, LView, LViewFlags, TView} from '../interfaces/view';
import {FLAGS, InitPhaseState, LView, LViewFlags, TVIEW, TView} from '../interfaces/view';
import {getLView, getSelectedIndex, getTView, isInCheckNoChangesMode, setSelectedIndex} from '../state';


Expand Down Expand Up @@ -43,7 +43,7 @@ export function ɵɵadvance(delta: number): void {

export function selectIndexInternal(
tView: TView, lView: LView, index: number, checkNoChangesMode: boolean) {
ngDevMode && assertIndexInDeclRange(lView, index);
ngDevMode && assertIndexInDeclRange(lView[TVIEW], index);

// Flush the initial hooks for elements in the view that have been added up to this point.
// PERF WARNING: do NOT extract this to a separate function without running benchmarks
Expand Down
Loading

0 comments on commit d61ff74

Please sign in to comment.