8000 refactor(core): expose `previousValue` as undefined by JeanMeche · Pull Request #67532 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions goldens/public-api/core/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1799,16 +1799,20 @@ export type Signal<T> = (() => T) & {
export function signal<T>(initialValue: T, options?: CreateSignalOptions<T>): WritableSignal<T>;

// @public
export class SimpleChange<T = any> {
constructor(previousValue: T, currentValue: T, firstChange: boolean);
// (undocumented)
export type SimpleChange<T = any> = {
previousValue: T;
currentValue: T;
// (undocumented)
firstChange: boolean;
firstChange: false;
isFirstChange(): false;
} | {
previousValue: T | undefined;
currentValue: T;
firstChange: true;
isFirstChange(): boolean;
// (undocumented)
previousValue: T;
}
};

// @public (undocumented)
export const SimpleChange: ɵSimpleChangeCtor;

// @public
export type SimpleChanges<T = unknown> = T extends object ? {
Expand Down
30 changes: 23 additions & 7 deletions packages/core/src/change_detection/simple_change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,35 @@ import type {ɵINPUT_SIGNAL_BRAND_READ_TYPE} from '../authoring/input/input_sign
*
* @publicApi
*/
export class SimpleChange<T = any> {
export type SimpleChange<T = any> =
| {
previousValue: T;
currentValue: T;
firstChange: false;
isFirstChange(): false;
}
| {
previousValue: T | undefined;
currentValue: T;
firstChange: true;
isFirstChange(): boolean;
};

export interface ɵSimpleChangeCtor {
new (previousValue: unknown, currentValue: unknown, firstChange: boolean): SimpleChange<any>;
}

export const SimpleChange: ɵSimpleChangeCtor = class SimpleChange {
constructor(
public previousValue: T,
public currentValue: T,
public previousValue: unknown,
public currentValue: unknown,
public firstChange: boolean,
) {}
/**
* Check whether the new value is the first value assigned.
*/

isFirstChange(): boolean {
return this.firstChange;
}
}
} as ɵSimpleChangeCtor;

/**
* A hashtable of changes represented by {@link SimpleChange} objects stored
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/render3/features/ng_onchanges_feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

import {InputSignalNode} from '../../authoring/input/input_signal_node';
import {OnChanges} from '../../change_detection/lifecycle_hooks';
import {SimpleChange, SimpleChanges} from '../../change_detection/simple_change';
import {assertString} from '../../util/assert';
import {EMPTY_OBJ} from '../../util/empty';
import {applyValueToInputField} from '../apply_value_input_field';
import {DirectiveDef, DirectiveDefFeature} from '../interfaces/definition';
import {SimpleChange, SimpleChanges} from '../../change_detection/simple_change';

/**
* The NgOnChangesFeature decorates a component with support for the ngOnChanges
Expand Down
0