fix(core): remove side effects from ɵɵNgOnChangesFeature()
(#35769)
`ɵɵNgOnChangesFeature()` would set `ngInherit`, which is a side effect and also not necessary. This was pulled out to module scope so the function itself can be pure. Since it only curries another function, the call is entirely unnecessary. Updated the compiler to only generate a reference to this function, rather than a call to it, and removed the extra curry indirection. PR Close #35769
This commit is contained in:
@ -35,26 +35,26 @@ type OnChangesExpando = OnChanges & {
|
||||
* static ɵcmp = defineComponent({
|
||||
* ...
|
||||
* inputs: {name: 'publicName'},
|
||||
* features: [NgOnChangesFeature()]
|
||||
* features: [NgOnChangesFeature]
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @codeGenApi
|
||||
*/
|
||||
export function ɵɵNgOnChangesFeature<T>(): DirectiveDefFeature {
|
||||
// This option ensures that the ngOnChanges lifecycle hook will be inherited
|
||||
// from superclasses (in InheritDefinitionFeature).
|
||||
(NgOnChangesFeatureImpl as DirectiveDefFeature).ngInherit = true;
|
||||
return NgOnChangesFeatureImpl;
|
||||
}
|
||||
|
||||
function NgOnChangesFeatureImpl<T>(definition: DirectiveDef<T>): void {
|
||||
export function ɵɵNgOnChangesFeature<T>(definition: DirectiveDef<T>): void {
|
||||
if (definition.type.prototype.ngOnChanges) {
|
||||
definition.setInput = ngOnChangesSetInput;
|
||||
(definition as{onChanges: Function}).onChanges = wrapOnChanges();
|
||||
}
|
||||
}
|
||||
|
||||
// This option ensures that the ngOnChanges lifecycle hook will be inherited
|
||||
// from superclasses (in InheritDefinitionFeature).
|
||||
/** @nocollapse */
|
||||
// tslint:disable-next-line:no-toplevel-property-access
|
||||
(ɵɵNgOnChangesFeature as DirectiveDefFeature).ngInherit = true;
|
||||
|
||||
function wrapOnChanges() {
|
||||
return function wrapOnChangesHook_inPreviousChangesStorage(this: OnChanges) {
|
||||
const simpleChangesStore = getSimpleChangesStore(this);
|
||||
|
Reference in New Issue
Block a user