Skip to content

Commit 1650a85

Browse files
crisbetothePunderWoman
authored andcommitted
refactor(core): handle NO_CHANGE in bindingUpdated (#61557)
Updates the `bindingUpdated` function to handle `NO_CHANGE` instead of throwing. This will allow us to reuse instructions across more cases. PR Close #61557
1 parent 02bd5f8 commit 1650a85

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

packages/core/src/render3/bindings.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ export function getBinding(lView: LView, bindingIndex: number): any {
4242
* `CheckNoChangesMode`)
4343
*/
4444
export function bindingUpdated(lView: LView, bindingIndex: number, value: any): boolean {
45-
ngDevMode && assertNotSame(value, NO_CHANGE, 'Incoming value should never be NO_CHANGE.');
4645
ngDevMode &&
4746
assertLessThan(bindingIndex, lView.length, `Slot should have been initialized to NO_CHANGE`);
47+
48+
if (value === NO_CHANGE) {
49+
return false;
50+
}
51+
4852
const oldValue = lView[bindingIndex];
4953

5054
if (Object.is(oldValue, value)) {

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import {bindingUpdated} from '../bindings';
99
import {SanitizerFn} from '../interfaces/sanitization';
1010
import {getLView, getSelectedTNode, getTView, nextBindingIndex} from '../state';
11-
import {NO_CHANGE} from '../tokens';
1211
import {elementAttributeInternal, storePropertyBindingMetadata} from './shared';
1312

1413
/**
@@ -30,17 +29,13 @@ export function ɵɵattribute(
3029
sanitizer?: SanitizerFn | null,
3130
namespace?: string,
3231
): typeof ɵɵattribute {
32+
const lView = getLView();
3333
const bindingIndex = nextBindingIndex();
34-
35-
// Value can be `NO_CHANGE` in case of an interpolation.
36-
if (value !== NO_CHANGE) {
37-
const lView = getLView();
38-
if (bindingUpdated(lView, bindingIndex, value)) {
39-
const tView = getTView();
40-
const tNode = getSelectedTNode();
41-
elementAttributeInternal(tNode, lView, name, value, sanitizer, namespace);
42-
ngDevMode && storePropertyBindingMetadata(tView.data, tNode, 'attr.' + name, bindingIndex);
43-
}
34+
if (bindingUpdated(lView, bindingIndex, value)) {
35+
const tView = getTView();
36+
const tNode = getSelectedTNode();
37+
elementAttributeInternal(tNode, lView, name, value, sanitizer, namespace);
38+
ngDevMode && storePropertyBindingMetadata(tView.data, tNode, 'attr.' + name, bindingIndex);
4439
}
4540

4641
return ɵɵattribute;

0 commit comments

Comments
 (0)