@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
47 lines (46 loc) • 1.2 kB
TypeScript
import { OnlyKeysOfSpecificType } from '../_internals/guards';
/**
* @description
* Toggles a boolean property in the object.
* Accepts object of type T and key value of which is boolean.
* Toggles the property and returns a shallow copy of an object, while not mutating the original one.
*
* @example
*
* const state = {items: [1,2,3], loading: true};
*
* const updatedState = toggle(state, 'loading');
*
* // updatedState will be:
* // {items: [1,2,3], loading: false};
*
* @example
* // Usage with RxState
*
* export class ListComponent {
* readonly loadingChange$ = new Subject();
*
* constructor(
* private state: RxState<ComponentState>
* ) {
* // Reactive implementation
* state.connect(
* this.api.loadingChange$,
* (state, _) => {
* return toggle(state, 'isLoading');
* }
* );
* }
*
* // Imperative implementation
* toggleLoading(): void {
* this.set(toggle(state, 'isLoading'));
* }
* }
*
* @returns T
*
* @docsPage toggle
* @docsCategory transformation-helpers
*/
export declare function toggle<T extends object>(object: T, key: OnlyKeysOfSpecificType<T, boolean>): T;