UNPKG

@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

44 lines (43 loc) 1.15 kB
/** * @description * Accepts an object of type T, key of type K extends keyof T, and value of type T[K]. * Sets the property and returns a newly updated shallow copy of an object while not mutating the original one. * * @example * * const cat = {id: 1, type: 'cat', name: 'Fluffy'}; * * const renamedCat = setProp(cat, 'name', 'Bella'); * * // renamedCat will be: * // {id: 1, type: 'cat', name: 'Bella'}; * * @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 setProp(state, 'name', name); * } * ); * } * * // Imperative implementation * changeName(name: string): void { * this.state.set(setProp(this.get(), 'name', name)); * } * } * * @returns T * * @docsPage setProp * @docsCategory transformation-helpers */ export declare function setProp<T extends object, K extends keyof T>(object: T, key: K, value: T[K]): T;