Skip to content

Commit

Permalink
refactor(ivy): misc refactoring (#23154)
Browse files Browse the repository at this point in the history
PR Close #23154
  • Loading branch information
vicb authored and alxhub committed Apr 4, 2018
1 parent c560423 commit 5c8340a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/render3/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,6 @@ export function executeHooks(
*/
export function callHooks(data: any[], arr: HookData): void {
for (let i = 0; i < arr.length; i += 2) {
(arr[i | 1] as() => void).call(data[arr[i] as number]);
(arr[i + 1] as() => void).call(data[arr[i] as number]);
}
}
39 changes: 20 additions & 19 deletions packages/core/src/render3/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ const enum BindingDirection {
* @returns the previous state;
*/
export function enterView(newView: LView, host: LElementNode | LViewNode | null): LView {
const oldView = currentView;
const oldView: LView = currentView;
data = newView && newView.data;
directives = newView && newView.directives;
bindingIndex = newView && newView.bindingStartIndex || 0;
Expand All @@ -212,7 +212,7 @@ export function enterView(newView: LView, host: LElementNode | LViewNode | null)
currentView = newView;
currentQueries = newView && newView.queries;

return oldView !;
return oldView;
}

/**
Expand Down Expand Up @@ -249,7 +249,7 @@ export function setHostBindings(bindings: number[] | null): void {
for (let i = 0; i < bindings.length; i += 2) {
const dirIndex = bindings[i];
const def = defs[dirIndex] as DirectiveDef<any>;
def.hostBindings && def.hostBindings(dirIndex, bindings[i | 1]);
def.hostBindings && def.hostBindings(dirIndex, bindings[i + 1]);
}
}
}
Expand All @@ -258,7 +258,7 @@ export function setHostBindings(bindings: number[] | null): void {
function refreshChildComponents(components: number[] | null): void {
if (components != null) {
for (let i = 0; i < components.length; i += 2) {
componentRefresh(components[i], components[i | 1]);
componentRefresh(components[i], components[i + 1]);
}
}
}
Expand Down Expand Up @@ -514,13 +514,11 @@ export function renderComponentOrTemplate<T>(
*/
export function elementStart(
index: number, name: string, attrs?: string[] | null, localRefs?: string[] | null): RElement {
let node: LElementNode;
let native: RElement;
ngDevMode &&
assertNull(currentView.bindingStartIndex, 'elements should be created before any bindings');

native = renderer.createElement(name);
node = createLNode(index, LNodeType.Element, native !, null);
const native: RElement = renderer.createElement(name);
const node: LElementNode = createLNode(index, LNodeType.Element, native !, null);

if (attrs) setUpAttributes(native, attrs);
appendChild(node.parent !, native, currentView);
Expand All @@ -538,8 +536,8 @@ export function elementStart(
}

function cacheMatchingDirectivesForNode(tNode: TNode): void {
const registry = currentView.tView.directiveRegistry;
const startIndex = directives ? directives.length : 0;
const tView = currentView.tView;
const registry = tView.directiveRegistry;

if (registry) {
let componentFlag = 0;
Expand All @@ -552,11 +550,14 @@ function cacheMatchingDirectivesForNode(tNode: TNode): void {
if (componentFlag) throwMultipleComponentError(tNode);
componentFlag |= TNodeFlags.Component;
}
(currentView.tView.directives || (currentView.tView.directives = [])).push(def);
(tView.directives || (tView.directives = [])).push(def);
size++;
}
}
if (size > 0) buildTNodeFlags(tNode, startIndex, size, componentFlag);
if (size > 0) {
const startIndex = directives ? directives.length : 0;
buildTNodeFlags(tNode, startIndex, size, componentFlag);
}
}
}

Expand Down Expand Up @@ -634,8 +635,8 @@ function cacheMatchingLocalNames(
// in the template to ensure the data is loaded in the same slots as their refs
// in the template (for template queries).
for (let i = 0; i < localRefs.length; i += 2) {
const index = exportsMap[localRefs[i | 1]];
if (index == null) throw new Error(`Export of name '${localRefs[i | 1]}' not found!`);
const index = exportsMap[localRefs[i + 1]];
if (index == null) throw new Error(`Export of name '${localRefs[i + 1]}' not found!`);
localNames.push(localRefs[i], index);
}
}
Expand All @@ -662,7 +663,7 @@ function saveResolvedLocalsInData(): void {
const localNames = previousOrParentNode.tNode !.localNames;
if (localNames) {
for (let i = 0; i < localNames.length; i += 2) {
const index = localNames[i | 1] as number;
const index = localNames[i + 1] as number;
const value = index === -1 ? previousOrParentNode.native : directives ![index];
data.push(value);
}
Expand Down Expand Up @@ -829,7 +830,7 @@ export function listener(
function createOutput(outputs: PropertyAliasValue, listener: Function): void {
for (let i = 0; i < outputs.length; i += 2) {
ngDevMode && assertDataInRange(outputs[i] as number, directives !);
const subscription = directives ![outputs[i] as number][outputs[i | 1]].subscribe(listener);
const subscription = directives ![outputs[i] as number][outputs[i + 1]].subscribe(listener);
cleanup !.push(subscription.unsubscribe, subscription);
}
}
Expand Down Expand Up @@ -944,7 +945,7 @@ function createTNode(
function setInputsForProperty(inputs: PropertyAliasValue, value: any): void {
for (let i = 0; i < inputs.length; i += 2) {
ngDevMode && assertDataInRange(inputs[i] as number, directives !);
directives ![inputs[i] as number][inputs[i | 1]] = value;
directives ![inputs[i] as number][inputs[i + 1]] = value;
}
}

Expand Down Expand Up @@ -1264,7 +1265,7 @@ function setInputsFromAttrs<T>(
const initialInputs: InitialInputs|null = initialInputData[directiveIndex];
if (initialInputs) {
for (let i = 0; i < initialInputs.length; i += 2) {
(instance as any)[initialInputs[i]] = initialInputs[i | 1];
(instance as any)[initialInputs[i]] = initialInputs[i + 1];
}
}
}
Expand Down Expand Up @@ -1296,7 +1297,7 @@ function generateInitialInputs(
if (minifiedInputName !== undefined) {
const inputsToStore: InitialInputs =
initialInputData[directiveIndex] || (initialInputData[directiveIndex] = []);
inputsToStore.push(minifiedInputName, attrs[i | 1]);
inputsToStore.push(minifiedInputName, attrs[i + 1]);
}
}
return initialInputData;
Expand Down
3 changes: 0 additions & 3 deletions packages/core/src/render3/interfaces/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,6 @@ export interface TView {
/**
* Full registry of directives and components that may be found in this view.
*
* The property is either an array of `DirectiveDef`s or a function which returns the array of
* `DirectiveDef`s. The function is necessary to be able to support forward declarations.
*
* It's necessary to keep a copy of the full def list on the TView so it's possible
* to render template functions without a host component.
*/
Expand Down

0 comments on commit 5c8340a

Please sign in to comment.