Skip to content

Commit 931d356

Browse files
committed
Revert "feat(ivy): add property instruction (angular#29513)"
This reverts commit e4c1c88.
1 parent e4c1c88 commit 931d356

File tree

3 files changed

+7
-185
lines changed

3 files changed

+7
-185
lines changed

packages/core/src/render3/instructions/instructions.ts

Lines changed: 5 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {Type} from '../../interface/type';
1313
import {CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, SchemaMetadata} from '../../metadata/schema';
1414
import {validateAgainstEventAttributes, validateAgainstEventProperties} from '../../sanitization/sanitization';
1515
import {Sanitizer} from '../../sanitization/security';
16-
import {assertDataInRange, assertDefined, assertDomNode, assertEqual, assertGreaterThan, assertLessThan, assertNotEqual} from '../../util/assert';
16+
import {assertDataInRange, assertDefined, assertDomNode, assertEqual, assertLessThan, assertNotEqual} from '../../util/assert';
1717
import {isObservable} from '../../util/lang';
1818
import {normalizeDebugBindingName, normalizeDebugBindingValue} from '../../util/ng_reflect';
1919
import {assertHasParent, assertLContainerOrUndefined, assertLView, assertPreviousIsParent} from '../assert';
@@ -37,7 +37,7 @@ import {assertNodeOfPossibleTypes, assertNodeType} from '../node_assert';
3737
import {appendChild, appendProjectedNodes, createTextNode, insertView, removeView} from '../node_manipulation';
3838
import {isNodeMatchingSelectorList, matchingProjectionSelectorIndex} from '../node_selector_matcher';
3939
import {applyOnCreateInstructions} from '../node_util';
40-
import {decreaseElementDepthCount, enterView, getActiveHostContext, getBindingsEnabled, getCheckNoChangesMode, getContextLView, getCurrentDirectiveDef, getElementDepthCount, getIsParent, getLView, getPreviousOrParentTNode, getSelectedIndex, increaseElementDepthCount, isCreationMode, leaveView, nextContextImpl, resetComponentState, setActiveHost, setBindingRoot, setCheckNoChangesMode, setCurrentDirectiveDef, setCurrentQueryIndex, setIsParent, setPreviousOrParentTNode, setSelectedIndex} from '../state';
40+
import {decreaseElementDepthCount, enterView, getActiveHostContext, getBindingsEnabled, getCheckNoChangesMode, getContextLView, getCurrentDirectiveDef, getElementDepthCount, getIsParent, getLView, getPreviousOrParentTNode, increaseElementDepthCount, isCreationMode, leaveView, nextContextImpl, resetComponentState, setActiveHost, setBindingRoot, setCheckNoChangesMode, setCurrentDirectiveDef, setCurrentQueryIndex, setIsParent, setPreviousOrParentTNode} from '../state';
4141
import {getInitialClassNameValue, getInitialStyleStringValue, initializeStaticContext as initializeStaticStylingContext, patchContextWithStaticAttrs, renderInitialClasses, renderInitialStyles} from '../styling/class_and_style_bindings';
4242
import {ANIMATION_PROP_PREFIX, getStylingContext, hasClassInput, hasStyleInput, isAnimationProp} from '../styling/util';
4343
import {NO_CHANGE} from '../tokens';
@@ -408,10 +408,6 @@ export function renderEmbeddedTemplate<T>(viewToRender: LView, tView: TView, con
408408
oldView = enterView(viewToRender, viewToRender[T_HOST]);
409409
resetPreOrderHookFlags(viewToRender);
410410
namespaceHTML();
411-
412-
// Reset the selected index so we can assert that `select` was called later
413-
ngDevMode && setSelectedIndex(-1);
414-
415411
tView.template !(getRenderFlags(viewToRender), context);
416412
// This must be set to false immediately after the first creation run because in an
417413
// ngFor loop, all the views will be created together before update mode runs and turns
@@ -457,10 +453,6 @@ function renderComponentOrTemplate<T>(
457453
// creation mode pass
458454
if (templateFn) {
459455
namespaceHTML();
460-
461-
// Reset the selected index so we can assert that `select` was called later
462-
ngDevMode && setSelectedIndex(-1);
463-
464456
templateFn(RenderFlags.Create, context);
465457
}
466458

@@ -1101,30 +1093,11 @@ export function elementEnd(): void {
11011093

11021094

11031095
/**
1104-
* Selects an index of an item to act on and flushes lifecycle hooks up to this point
1096+
* Flushes all the lifecycle hooks for directives up until (and excluding) that node index
11051097
*
1106-
* Used in conjunction with instructions like {@link property} to act on elements with specified
1107-
* indices, for example those created with {@link element} or {@link elementStart}.
1108-
*
1109-
* ```ts
1110-
* (rf: RenderFlags, ctx: any) => {
1111-
* if (rf & 1) {
1112-
* element(0, 'div');
1113-
* }
1114-
* if (rf & 2) {
1115-
* select(0); // Select the <div/> created above.
1116-
* property('title', 'test');
1117-
* }
1118-
* }
1119-
* ```
1120-
* @param index the index of the item to act on with the following instructions
1121-
*/
1098+
* @param index The index of the element in the `LView`
1099+
*/
11221100
export function select(index: number): void {
1123-
ngDevMode && assertGreaterThan(index, -1, 'Invalid index');
1124-
ngDevMode &&
1125-
assertLessThan(
1126-
index, getLView().length - HEADER_OFFSET, 'Should be within range for the view data');
1127-
setSelectedIndex(index);
11281101
const lView = getLView();
11291102
executePreOrderHooks(lView, lView[TVIEW], getCheckNoChangesMode(), index);
11301103
}
@@ -1169,34 +1142,6 @@ export function elementAttribute(
11691142
}
11701143

11711144
/**
1172-
* Update a property on a selected element.
1173-
*
1174-
* Operates on the element selected by index via the {@link select} instruction.
1175-
*
1176-
* If the property name also exists as an input property on one of the element's directives,
1177-
* the component property will be set instead of the element property. This check must
1178-
* be conducted at runtime so child components that add new `@Inputs` don't have to be re-compiled
1179-
*
1180-
* @param propName Name of property. Because it is going to DOM, this is not subject to
1181-
* renaming as part of minification.
1182-
* @param value New value to write.
1183-
* @param sanitizer An optional function used to sanitize the value.
1184-
* @param nativeOnly Whether or not we should only set native properties and skip input check
1185-
* (this is necessary for host property bindings)
1186-
* @returns This function returns itself so that it may be chained
1187-
* (e.g. `property('name', ctx.name)('title', ctx.title)`)
1188-
*/
1189-
export function property<T>(
1190-
propName: string, value: T, sanitizer?: SanitizerFn | null,
1191-
nativeOnly?: boolean): typeof property {
1192-
const index = getSelectedIndex();
1193-
const bindReconciledValue = bind(value);
1194-
elementPropertyInternal(index, propName, bindReconciledValue, sanitizer, nativeOnly);
1195-
return property;
1196-
}
1197-
1198-
/**
1199-
* **TODO: Remove this function after `property` is in use**
12001145
* Update a property on an element.
12011146
*
12021147
* If the property name also exists as an input property on one of the element's directives,
@@ -2703,12 +2648,7 @@ export function checkView<T>(hostView: LView, component: T) {
27032648
resetPreOrderHookFlags(hostView);
27042649
namespaceHTML();
27052650
creationMode && executeViewQueryFn(RenderFlags.Create, hostTView, component);
2706-
2707-
// Reset the selected index so we can assert that `select` was called later
2708-
ngDevMode && setSelectedIndex(-1);
2709-
27102651
templateFn(getRenderFlags(hostView), component);
2711-
27122652
refreshDescendantViews(hostView);
27132653
// Only check view queries again in creation mode if there are static view queries
27142654
if (!creationMode || hostTView.staticViewQueries) {

packages/core/src/render3/state.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {assertDefined, assertGreaterThan} from '../util/assert';
9+
import {assertDefined} from '../util/assert';
1010

1111
import {assertLViewOrUndefined} from './assert';
1212
import {executeHooks} from './hooks';
@@ -340,28 +340,3 @@ export function leaveView(newView: LView): void {
340340
}
341341
enterView(newView, null);
342342
}
343-
344-
let _selectedIndex = -1;
345-
346-
/**
347-
* Gets the most recent index passed to {@link select}
348-
*
349-
* Used with {@link property} instruction (and more in the future) to identify the index in the
350-
* current `LView` to act on.
351-
*/
352-
export function getSelectedIndex() {
353-
ngDevMode &&
354-
assertGreaterThan(
355-
_selectedIndex, -1, 'select() should be called prior to retrieving the selected index');
356-
return _selectedIndex;
357-
}
358-
359-
/**
360-
* Sets the most recent index passed to {@link select}
361-
*
362-
* Used with {@link property} instruction (and more in the future) to identify the index in the
363-
* current `LView` to act on.
364-
*/
365-
export function setSelectedIndex(index: number) {
366-
_selectedIndex = index;
367-
}

packages/core/test/render3/instructions_spec.ts

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {NgForOfContext} from '@angular/common';
1010

1111
import {RenderFlags} from '../../src/render3';
1212
import {defineComponent} from '../../src/render3/definition';
13-
import {bind, element, elementAttribute, elementEnd, elementProperty, elementStart, elementStyleProp, elementStyling, elementStylingApply, elementStylingMap, interpolation1, renderTemplate, template, text, textBinding, select, property} from '../../src/render3/instructions/all';
13+
import {bind, element, elementAttribute, elementEnd, elementProperty, elementStart, elementStyleProp, elementStyling, elementStylingApply, elementStylingMap, interpolation1, renderTemplate, template, text, textBinding} from '../../src/render3/instructions/all';
1414
import {AttributeMarker} from '../../src/render3/interfaces/node';
1515
import {bypassSanitizationTrustHtml, bypassSanitizationTrustResourceUrl, bypassSanitizationTrustScript, bypassSanitizationTrustStyle, bypassSanitizationTrustUrl} from '../../src/sanitization/bypass';
1616
import {defaultStyleSanitizer, sanitizeHtml, sanitizeResourceUrl, sanitizeScript, sanitizeStyle, sanitizeUrl} from '../../src/sanitization/sanitization';
@@ -19,7 +19,6 @@ import {StyleSanitizeFn} from '../../src/sanitization/style_sanitizer';
1919

2020
import {NgForOf} from './common_with_def';
2121
import {ComponentFixture, TemplateFixture} from './render_util';
22-
import {setSelectedIndex, getSelectedIndex} from '@angular/core/src/render3/state';
2322

2423
describe('instructions', () => {
2524
function createAnchor() {
@@ -163,98 +162,6 @@ describe('instructions', () => {
163162
});
164163
});
165164

166-
describe('select', () => {
167-
it('should error in DevMode if index is out of range', () => {
168-
// Only one constant added, meaning only index `0` is valid.
169-
const t = new TemplateFixture(createDiv, () => {}, 1, 0);
170-
expect(() => { t.update(() => { select(-1); }); }).toThrow();
171-
expect(() => { t.update(() => { select(1); }); }).toThrow();
172-
expect(() => { t.update(() => { select(0); }); }).not.toThrow();
173-
});
174-
});
175-
176-
describe('property', () => {
177-
// TODO(benlesh): Replace with TestBed tests once the instruction is being generated.
178-
it('should set properties of the selected element', () => {
179-
// <div [title]="title"></div>
180-
const t = new TemplateFixture(createDiv, () => {}, 1, 1);
181-
t.update(() => {
182-
select(0);
183-
property('title', 'one');
184-
});
185-
expect(t.html).toEqual('<div title="one"></div>');
186-
t.update(() => {
187-
select(0);
188-
property('title', 'two');
189-
});
190-
expect(t.html).toEqual('<div title="two"></div>');
191-
expect(ngDevMode).toHaveProperties({
192-
firstTemplatePass: 1,
193-
tNode: 2, // 1 for div, 1 for host element
194-
tView: 2, // 1 for rootView + 1 for the template view
195-
rendererCreateElement: 1,
196-
rendererSetProperty: 2,
197-
});
198-
});
199-
200-
// TODO(benlesh): Replace with TestBed tests once the instruction is being generated.
201-
it('should chain', () => {
202-
// <div [title]="title" [accesskey]="key"></div>
203-
const t = new TemplateFixture(createDiv, () => {}, 1, 2);
204-
t.update(() => {
205-
select(0);
206-
property('title', 'one')('accessKey', 'A');
207-
});
208-
expect(t.html).toEqual('<div accesskey="A" title="one"></div>');
209-
t.update(() => {
210-
select(0);
211-
property('title', 'two')('accessKey', 'B');
212-
});
213-
expect(t.html).toEqual('<div accesskey="B" title="two"></div>');
214-
expect(ngDevMode).toHaveProperties({
215-
firstTemplatePass: 1,
216-
tNode: 2, // 1 for div, 1 for host element
217-
tView: 2, // 1 for rootView + 1 for the template view
218-
rendererCreateElement: 1,
219-
rendererSetProperty: 4,
220-
});
221-
});
222-
223-
// TODO(benlesh): Replace with TestBed tests once the instruction is being generated.
224-
it('should diff value changes', () => {
225-
// <div [title]="title" [accesskey]="key"></div>
226-
const t = new TemplateFixture(createDiv, () => {}, 1, 2);
227-
t.update(() => {
228-
select(0);
229-
property('title', 'one')('accessKey', 'A');
230-
});
231-
expect(t.html).toEqual('<div accesskey="A" title="one"></div>');
232-
t.update(() => {
233-
select(0);
234-
property('title', 'two')('accessKey', 'A'); // Notice: only changing the title.
235-
});
236-
expect(t.html).toEqual('<div accesskey="A" title="two"></div>');
237-
expect(ngDevMode).toHaveProperties({
238-
firstTemplatePass: 1,
239-
tNode: 2, // 1 for div, 1 for host element
240-
tView: 2, // 1 for rootView + 1 for the template view
241-
rendererCreateElement: 1,
242-
rendererSetProperty: 3,
243-
});
244-
});
245-
246-
it('should error in dev mode if select was not called prior', () => {
247-
const t = new TemplateFixture(createDiv, () => {}, 1, 1);
248-
expect(() => { t.update(() => { property('title', 'test'); }); }).toThrow();
249-
expect(() => {
250-
t.update(() => {
251-
select(0);
252-
property('title', 'test');
253-
});
254-
}).not.toThrow();
255-
});
256-
});
257-
258165
describe('elementProperty', () => {
259166
it('should use sanitizer function when available', () => {
260167
const t = new TemplateFixture(createDiv, () => {}, 1);

0 commit comments

Comments
 (0)