From 9106271f2c64169a84ddd375fc269216dd3a202a Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Fri, 2 Aug 2019 14:25:52 +0200 Subject: [PATCH] refactor(ivy): remove dependency on global state from isCreationMode (#31959) PR Close #31959 --- packages/core/src/render3/instructions/embedded_view.ts | 4 ++-- packages/core/src/render3/instructions/shared.ts | 6 +++--- packages/core/src/render3/pure_function.ts | 6 +++--- packages/core/src/render3/query.ts | 5 +++-- packages/core/src/render3/state.ts | 8 +------- packages/core/src/render3/util/view_utils.ts | 5 +++++ 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/core/src/render3/instructions/embedded_view.ts b/packages/core/src/render3/instructions/embedded_view.ts index bcfc8d4a9a..19b06480df 100644 --- a/packages/core/src/render3/instructions/embedded_view.ts +++ b/packages/core/src/render3/instructions/embedded_view.ts @@ -14,8 +14,8 @@ import {TContainerNode, TNodeType} from '../interfaces/node'; import {FLAGS, LView, LViewFlags, PARENT, TVIEW, TView, T_HOST} from '../interfaces/view'; import {assertNodeType} from '../node_assert'; import {insertView, removeView} from '../node_manipulation'; -import {enterView, getIsParent, getLView, getPreviousOrParentTNode, isCreationMode, leaveView, setIsParent, setPreviousOrParentTNode} from '../state'; -import {resetPreOrderHookFlags} from '../util/view_utils'; +import {enterView, getIsParent, getLView, getPreviousOrParentTNode, leaveView, setIsParent, setPreviousOrParentTNode} from '../state'; +import {isCreationMode, resetPreOrderHookFlags} from '../util/view_utils'; import {assignTViewNodeToLView, createLView, createTView, refreshDescendantViews} from './shared'; /** diff --git a/packages/core/src/render3/instructions/shared.ts b/packages/core/src/render3/instructions/shared.ts index f22dfd9d2c..512bb313a0 100644 --- a/packages/core/src/render3/instructions/shared.ts +++ b/packages/core/src/render3/instructions/shared.ts @@ -28,13 +28,13 @@ import {isComponent, isComponentDef, isContentQueryHost, isLContainer, isRootVie 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, assertNodeType} from '../node_assert'; import {isNodeMatchingSelectorList} from '../node_selector_matcher'; -import {enterView, getBindingsEnabled, getCheckNoChangesMode, getIsParent, getLView, getNamespace, getPreviousOrParentTNode, getSelectedIndex, incrementActiveDirectiveId, isCreationMode, leaveView, namespaceHTMLInternal, setActiveHostElement, setBindingRoot, setCheckNoChangesMode, setCurrentDirectiveDef, setCurrentQueryIndex, setPreviousOrParentTNode, setSelectedIndex} from '../state'; +import {enterView, getBindingsEnabled, getCheckNoChangesMode, getIsParent, getLView, getPreviousOrParentTNode, getSelectedIndex, incrementActiveDirectiveId, leaveView, namespaceHTMLInternal, setActiveHostElement, setBindingRoot, setCheckNoChangesMode, setCurrentDirectiveDef, setCurrentQueryIndex, setPreviousOrParentTNode, setSelectedIndex} from '../state'; import {renderStylingMap} from '../styling_next/bindings'; import {NO_CHANGE} from '../tokens'; import {ANIMATION_PROP_PREFIX, isAnimationProp} from '../util/attrs_utils'; import {INTERPOLATION_DELIMITER, renderStringify, stringifyForError} from '../util/misc_utils'; -import {getLViewParent, getRootContext} from '../util/view_traversal_utils'; -import {getComponentViewByIndex, getNativeByIndex, getNativeByTNode, getTNode, readPatchedLView, resetPreOrderHookFlags, unwrapRNode, viewAttachedToChangeDetector} from '../util/view_utils'; +import {getLViewParent} from '../util/view_traversal_utils'; +import {getComponentViewByIndex, getNativeByIndex, getNativeByTNode, getTNode, isCreationMode, readPatchedLView, resetPreOrderHookFlags, unwrapRNode, viewAttachedToChangeDetector} from '../util/view_utils'; import {LCleanup, LViewBlueprint, MatchesArray, TCleanup, TNodeConstructor, TNodeInitialData, TNodeInitialInputs, TNodeLocalNames, TViewComponents, TViewConstructor, attachLContainerDebug, attachLViewDebug, cloneToLView, cloneToTViewData} from './lview_debug'; import {selectInternal} from './select'; diff --git a/packages/core/src/render3/pure_function.ts b/packages/core/src/render3/pure_function.ts index d3a893ba6d..62f3fd7ea2 100644 --- a/packages/core/src/render3/pure_function.ts +++ b/packages/core/src/render3/pure_function.ts @@ -7,8 +7,8 @@ */ import {bindingUpdated, bindingUpdated2, bindingUpdated3, bindingUpdated4, getBinding, updateBinding} from './bindings'; -import {getBindingRoot, getLView, isCreationMode} from './state'; - +import {getBindingRoot, getLView} from './state'; +import {isCreationMode} from './util/view_utils'; /** @@ -44,7 +44,7 @@ export function ɵɵpureFunction0(slotOffset: number, pureFn: () => T, thisAr // TODO(kara): use bindingRoot instead of bindingStartIndex when implementing host bindings const bindingIndex = getBindingRoot() + slotOffset; const lView = getLView(); - return isCreationMode() ? + return isCreationMode(lView) ? updateBinding(lView, bindingIndex, thisArg ? pureFn.call(thisArg) : pureFn()) : getBinding(lView, bindingIndex); } diff --git a/packages/core/src/render3/query.ts b/packages/core/src/render3/query.ts index 4521f7ed6e..0efbaf0c9c 100644 --- a/packages/core/src/render3/query.ts +++ b/packages/core/src/render3/query.ts @@ -27,7 +27,8 @@ import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType, u import {LQueries, LQuery, TQueries, TQuery, TQueryMetadata, unusedValueExportToPlacateAjd as unused4} from './interfaces/query'; import {DECLARATION_LCONTAINER, LView, PARENT, QUERIES, TVIEW, TView} from './interfaces/view'; import {assertNodeOfPossibleTypes} from './node_assert'; -import {getCurrentQueryIndex, getLView, getPreviousOrParentTNode, isCreationMode, setCurrentQueryIndex} from './state'; +import {getCurrentQueryIndex, getLView, getPreviousOrParentTNode, setCurrentQueryIndex} from './state'; +import {isCreationMode} from './util/view_utils'; import {createContainerRef, createElementRef, createTemplateRef} from './view_engine_compatibility'; const unusedValueToPlacateAjd = unused1 + unused2 + unused3 + unused4; @@ -392,7 +393,7 @@ export function ɵɵqueryRefresh(queryList: QueryList): boolean { setCurrentQueryIndex(queryIndex + 1); const tQuery = getTQuery(lView[TVIEW], queryIndex); - if (queryList.dirty && (isCreationMode() === tQuery.metadata.isStatic)) { + if (queryList.dirty && (isCreationMode(lView) === tQuery.metadata.isStatic)) { if (tQuery.matches === null) { queryList.reset([]); } else { diff --git a/packages/core/src/render3/state.ts b/packages/core/src/render3/state.ts index a162ae1edb..0add34b244 100644 --- a/packages/core/src/render3/state.ts +++ b/packages/core/src/render3/state.ts @@ -15,7 +15,7 @@ import {ComponentDef, DirectiveDef} from './interfaces/definition'; import {TElementNode, TNode, TViewNode} from './interfaces/node'; import {BINDING_INDEX, CONTEXT, DECLARATION_VIEW, FLAGS, InitPhaseState, LView, LViewFlags, OpaqueViewState, TVIEW} from './interfaces/view'; import {resetAllStylingState, resetStylingState} from './styling_next/state'; -import {resetPreOrderHookFlags} from './util/view_utils'; +import {isCreationMode, resetPreOrderHookFlags} from './util/view_utils'; @@ -334,12 +334,6 @@ export function setIsParent(): void { isParent = true; } - -/** Checks whether a given view is in creation mode */ -export function isCreationMode(view: LView = lView): boolean { - return (view[FLAGS] & LViewFlags.CreationMode) === LViewFlags.CreationMode; -} - /** * State of the current view being processed. * diff --git a/packages/core/src/render3/util/view_utils.ts b/packages/core/src/render3/util/view_utils.ts index a451367d7e..ab1dc31bc1 100644 --- a/packages/core/src/render3/util/view_utils.ts +++ b/packages/core/src/render3/util/view_utils.ts @@ -158,6 +158,11 @@ export function readPatchedLView(target: any): LView|null { return null; } +/** Checks whether a given view is in creation mode */ +export function isCreationMode(view: LView): boolean { + return (view[FLAGS] & LViewFlags.CreationMode) === LViewFlags.CreationMode; +} + /** * Returns a boolean for whether the view is attached to the change detection tree. *