Skip to content

Commit

Permalink
fixup! refactor(ivy): Intruduce LFrame to store global instruction in…
Browse files Browse the repository at this point in the history
…formation
  • Loading branch information
mhevery committed Oct 15, 2019
1 parent 4ea43d9 commit a918cb7
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 51 deletions.
7 changes: 1 addition & 6 deletions packages/core/src/render3/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {TElementNode, TNode, TNodeType} from './interfaces/node';
import {PlayerHandler} from './interfaces/player';
import {RElement, Renderer3, RendererFactory3, domRendererFactory3} from './interfaces/renderer';
import {CONTEXT, HEADER_OFFSET, LView, LViewFlags, RootContext, RootContextFlags, TVIEW} from './interfaces/view';
import {enterView, getPreviousOrParentTNode, incrementActiveDirectiveId, leaveViewProcessExit, resetComponentState, setActiveHostElement} from './state';
import {enterView, getPreviousOrParentTNode, incrementActiveDirectiveId, leaveViewProcessExit, setActiveHostElement} from './state';
import {publishDefaultGlobalUtils} from './util/global_utils';
import {defaultScheduler, stringifyForError} from './util/misc_utils';
import {getRootContext} from './util/view_traversal_utils';
Expand Down Expand Up @@ -111,10 +111,6 @@ export function renderComponent<T>(
ngDevMode && publishDefaultGlobalUtils();
ngDevMode && assertComponentType(componentType);

// this is preemptively set to avoid having test and debug code accidentally
// read data from a previous application state...
setActiveHostElement(null);

const rendererFactory = opts.rendererFactory || domRendererFactory3;
const sanitizer = opts.sanitizer || null;
const componentDef = getComponentDef<T>(componentType) !;
Expand Down Expand Up @@ -170,7 +166,6 @@ export function renderComponent<T>(
export function createRootComponentView(
rNode: RElement | null, def: ComponentDef<any>, rootView: LView,
rendererFactory: RendererFactory3, renderer: Renderer3, sanitizer?: Sanitizer | null): LView {
resetComponentState();
const tView = rootView[TVIEW];
ngDevMode && assertDataInRange(rootView, 0 + HEADER_OFFSET);
rootView[0 + HEADER_OFFSET] = rNode;
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/render3/instructions/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {isComponentDef, isComponentHost, isContentQueryHost, isLContainer, isRoo
import {BINDING_INDEX, CHILD_HEAD, CHILD_TAIL, CLEANUP, CONTEXT, DECLARATION_VIEW, ExpandoInstructions, FLAGS, HEADER_OFFSET, HOST, INJECTOR, InitPhaseState, LView, LViewFlags, NEXT, PARENT, RENDERER, RENDERER_FACTORY, RootContext, RootContextFlags, SANITIZER, TData, TVIEW, TView, T_HOST} from '../interfaces/view';
import {assertNodeOfPossibleTypes} from '../node_assert';
import {isNodeMatchingSelectorList} from '../node_selector_matcher';
import {ActiveElementFlags, enterView, executeElementExitFn, getBindingsEnabled, getCheckNoChangesMode, getIsParent, getPreviousOrParentTNode, getSelectedIndex, hasActiveElementFlag, incrementActiveDirectiveId, leaveViewProcessExit, setActiveHostElement, setBindingRoot, setCurrentDirectiveDef, setCurrentQueryIndex, setPreviousOrParentTNode, setSelectedIndex, setCheckNoChangesMode} from '../state';
import {ActiveElementFlags, enterView, executeElementExitFn, getBindingsEnabled, getCheckNoChangesMode, getIsParent, getPreviousOrParentTNode, getSelectedIndex, hasActiveElementFlag, incrementActiveDirectiveId, leaveViewProcessExit, setActiveHostElement, setBindingRoot, setCheckNoChangesMode, setCurrentDirectiveDef, setCurrentQueryIndex, setPreviousOrParentTNode, setSelectedIndex} from '../state';
import {renderStylingMap} from '../styling/bindings';
import {NO_CHANGE} from '../tokens';
import {isAnimationProp} from '../util/attrs_utils';
Expand Down Expand Up @@ -310,8 +310,7 @@ export function allocExpando(view: LView, numSlotsToAlloc: number) {
* - updating static queries (if any);
* - creating child components defined in a given view.
*/
export function renderView<T>(
lView: LView, tView: TView, context: T): void {
export function renderView<T>(lView: LView, tView: TView, context: T): void {
ngDevMode && assertEqual(isCreationMode(lView), true, 'Should be run in creation mode');
enterView(lView, lView[T_HOST]);
try {
Expand Down
35 changes: 17 additions & 18 deletions packages/core/src/render3/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {assertDefined, assertEqual} from '../util/assert';

import {assertLViewOrUndefined} from './assert';
import {ComponentDef, DirectiveDef} from './interfaces/definition';
import {TElementNode, TNode, TViewNode} from './interfaces/node';
import {CONTEXT, DECLARATION_VIEW, LView, OpaqueViewState} from './interfaces/view';
import {TNode} from './interfaces/node';
import {BINDING_INDEX, CONTEXT, DECLARATION_VIEW, LView, OpaqueViewState, TVIEW} from './interfaces/view';


/**
*
Expand Down Expand Up @@ -276,7 +277,7 @@ export function hasActiveElementFlag(flag: ActiveElementFlags) {
/**
* Sets a flag is for the active element.
*/
export function setActiveElementFlag(flag: ActiveElementFlags) {
function setActiveElementFlag(flag: ActiveElementFlags) {
instructionState.lFrame.selectedIndex |= flag;
}

Expand All @@ -288,14 +289,12 @@ export function setActiveElementFlag(flag: ActiveElementFlags) {
* the directive/component instance lives
*/
export function setActiveHostElement(elementIndex: number | null = null) {
if (getSelectedIndex() !== elementIndex) {
if (hasActiveElementFlag(ActiveElementFlags.RunExitFn)) {
executeElementExitFn();
}
setSelectedIndex(elementIndex === null ? -1 : elementIndex);
instructionState.lFrame.activeDirectiveId = 0;
}
}

export function executeElementExitFn() {
instructionState.elementExitFn !();
Expand Down Expand Up @@ -423,7 +422,13 @@ export function setCheckNoChangesMode(mode: boolean): void {

// top level variables should not be exported for performance reasons (PERF_NOTES.md)
export function getBindingRoot() {
return instructionState.lFrame.bindingRootIndex;
const lFrame = instructionState.lFrame;
let index = lFrame.bindingRootIndex;
if (index === -1) {
const lView = lFrame.lView;
index = lFrame.bindingRootIndex = lView[BINDING_INDEX] = lView[TVIEW].bindingStartIndex;
}
return index;
}

export function setBindingRoot(value: number) {
Expand Down Expand Up @@ -460,7 +465,7 @@ export function enterView(newView: LView, tNode: TNode | null): void {
previousOrParentTNode: tNode !,
isParent: true,
lView: newView,
selectedIndex: -1 << ActiveElementFlags.Size,
selectedIndex: 0,
contextLView: newView !,
elementDepthCount: 0,
currentNamespace: null,
Expand All @@ -470,6 +475,11 @@ export function enterView(newView: LView, tNode: TNode | null): void {
bindingRootIndex: -1,
currentQueryIndex: 0,
}

// TODO(misko): temporary workaround;
if (newView !== null) {
newView[BINDING_INDEX] = getBindingRoot();
}
}

export function leaveViewProcessExit() {
Expand Down Expand Up @@ -499,17 +509,6 @@ function walkUpViews(nestingLevel: number, currentView: LView): LView {
return currentView;
}

/**
* Resets the application state.
*/
export function resetComponentState() {
instructionState.lFrame.isParent = false;
instructionState.lFrame.previousOrParentTNode = null !;
instructionState.lFrame.elementDepthCount = 0;
instructionState.bindingsEnabled = true;
setCurrentStyleSanitizer(null);
}

/**
* Gets the most recent index passed to {@link select}
*
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/acceptance/styling_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ describe('styling', () => {
expect(readyChild).toBeTruthy();
});

onlyInIvy('only ivy allows for multiple styles/classes to be balanaced across directives')
onlyInIvy('only ivy allows for multiple styles/classes to be balanced across directives')
.it('should allow various duplicate properties to be defined in various styling maps within the template and directive styling bindings',
() => {
@Component({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,6 @@
{
"name": "renderView"
},
{
"name": "resetComponentState"
},
{
"name": "resetPreOrderHookFlags"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,6 @@
{
"name": "renderView"
},
{
"name": "resetComponentState"
},
{
"name": "resetPreOrderHookFlags"
},
Expand Down
3 changes: 0 additions & 3 deletions packages/core/test/bundling/todo/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -1151,9 +1151,6 @@
{
"name": "renderView"
},
{
"name": "resetComponentState"
},
{
"name": "resetPreOrderHookFlags"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {ɵɵdefineDirective, ɵɵelementEnd, ɵɵelementStart, ɵɵtext} from '.
import {createTNode, createTView} from '../../../../src/render3/instructions/shared';
import {RenderFlags} from '../../../../src/render3/interfaces/definition';
import {TNodeType, TViewNode} from '../../../../src/render3/interfaces/node';
import {resetComponentState} from '../../../../src/render3/state';
import {createBenchmark} from '../micro_bench';
import {createAndRenderLView} from '../setup';

Expand Down Expand Up @@ -78,9 +77,6 @@ const embeddedTView = createTView(
-1, testTemplate, 21, 10, [Tooltip.ngDirectiveDef], null, null, null,
[['position', 'top', 3, 'tooltip']]);

// initialize global state
resetComponentState();

// create view once so we don't profile first template pass
createAndRenderLView(null, embeddedTView, viewTNode);

Expand Down
4 changes: 0 additions & 4 deletions packages/core/test/render3/perf/element_text_create/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {createTNode, createTView} from '../../../../src/render3/instructions/sha
import {ɵɵtext} from '../../../../src/render3/instructions/text';
import {RenderFlags} from '../../../../src/render3/interfaces/definition';
import {TNodeType, TViewNode} from '../../../../src/render3/interfaces/node';
import {resetComponentState} from '../../../../src/render3/state';
import {createBenchmark} from '../micro_bench';
import {createAndRenderLView} from '../setup';

Expand Down Expand Up @@ -69,9 +68,6 @@ const embeddedTView = createTView(-1, testTemplate, 21, 0, null, null, null, nul
['name1', 'value1', 'name2', 'value2', 'name3', 'value3', 'name4', 'value4', 'name5', 'value5']
]);

// initialize global state
resetComponentState();

// create view once so we don't profile first template pass
createAndRenderLView(null, embeddedTView, viewTNode);

Expand Down
4 changes: 0 additions & 4 deletions packages/core/test/render3/perf/listeners/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {ɵɵlistener} from '../../../../src/render3/instructions/listener';
import {createTNode, createTView} from '../../../../src/render3/instructions/shared';
import {RenderFlags} from '../../../../src/render3/interfaces/definition';
import {TNodeType, TViewNode} from '../../../../src/render3/interfaces/node';
import {resetComponentState} from '../../../../src/render3/state';
import {createBenchmark} from '../micro_bench';
import {createAndRenderLView} from '../setup';

Expand Down Expand Up @@ -79,9 +78,6 @@ const viewTNode = createTNode(null !, null, TNodeType.View, -1, null, null) as T
const embeddedTView =
createTView(-1, testTemplate, 11, 0, null, null, null, null, [[3, 'click', 'input']]);

// initialize global state
resetComponentState();

// create view once so we don't profile first template pass
createAndRenderLView(null, embeddedTView, viewTNode);

Expand Down
3 changes: 1 addition & 2 deletions packages/core/test/render3/render_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {ViewContainerRef} from '@angular/core/src/linker/view_container_ref';
import {Renderer2} from '@angular/core/src/render/api';
import {createLView, createTView, getOrCreateTNode, getOrCreateTView, renderComponentOrTemplate} from '@angular/core/src/render3/instructions/shared';
import {TAttributes, TNodeType} from '@angular/core/src/render3/interfaces/node';
import {getLView, resetComponentState, enterView} from '@angular/core/src/render3/state';
import {getLView, enterView} from '@angular/core/src/render3/state';
import {stringifyElement} from '@angular/platform-browser/testing/src/browser_util';

import {SWITCH_CHANGE_DETECTOR_REF_FACTORY__POST_R3__ as R3_CHANGE_DETECTOR_REF_FACTORY} from '../../src/change_detection/change_detector_ref';
Expand Down Expand Up @@ -251,7 +251,6 @@ export function renderTemplate<T>(
directives?: DirectiveDefListOrFactory | null, pipes?: PipeDefListOrFactory | null,
sanitizer?: Sanitizer | null, consts?: TAttributes[]): LView {
if (componentView === null) {
resetComponentState();
const renderer = providedRendererFactory.createRenderer(null, null);

// We need to create a root view so it's possible to look up the host element through its index
Expand Down

0 comments on commit a918cb7

Please sign in to comment.