@rx-angular/cdk
Version:
@rx-angular/cdk is a Component Development Kit for ergonomic and highly performant angular applications. It helps to to build Large scale applications, UI libs, state management, rendering systems and much more. Furthermore the unique way of mixing reacti
49 lines (47 loc) • 1.14 kB
TypeScript
/**
* @description
* Merges an object of type T with updates of type Partial<T>.
* Returns a new object where updates override original values while not mutating the original one.
* @example
* interface Creature {
* id: number,
* type: string,
* name: string
* }
*
* const cat = {id: 1, type: 'cat'};
*
* const catWithname = patch(cat, {name: 'Fluffy'});
*
* // catWithname will be:
* // {id: 1, type: 'cat', name: 'Fluffy'};
*
* @example
* // Usage with RxState
*
* export class ProfileComponent {
*
* readonly changeName$ = new Subject<string>();
*
* constructor(private state: RxState<ComponentState>) {
* // Reactive implementation
* state.connect(
* this.changeName$,
* (state, name) => {
* return patch(state, { name });
* }
* );
* }
*
* // Imperative implementation
* changeName(name: string): void {
* this.state.set(patch(this.get(), { name }));
* }
* }
*
* @returns T
*
* @docsPage patch
* @docsCategory transformation-helpers
*/
export declare function patch<T extends object>(object: T, upd: Partial<T>): T;