@rx-angular/state
Version:
@rx-angular/state is a light-weight, flexible, strongly typed and tested tool dedicated to reduce the complexity of managing component state and side effects in angular
44 lines • 1.29 kB
TypeScript
import { SideEffectFnOrObserver, SideEffectObservable } from './types';
interface RxEffects {
register<T>(observable: SideEffectObservable<T>, sideEffectOrObserver?: SideEffectFnOrObserver<T>): Fn;
onDestroy: (fn: Fn) => Fn;
}
type Fn = () => void;
export type RxEffectsSetupFn = (cfg: Pick<RxEffects, 'register' | 'onDestroy'>) => void;
/**
* @description
* Functional way to setup observable based side effects with RxEffects.
* It's a creation function for RxEffects that destroys itself when the provided
* `DestroyRef` is destroyed.
*
* @example
* ```ts
* import { rxEffects } from '@rx-angular/state/effects';
*
* \@Component({})
* export class FooComponent {
* const readonly util = inject(Util);
* readonly effects = rxEffects(({ register }) => {
* register(this.util.windowResize$, () => {
* console.log('window was resized');
* })
* });
*
* ngOnInit() {
* this.effects.register(this.util.rotationChanged$, () => {
* console.log('viewport rotation changed');
* });
* }
* }
* ```
*
* @param {RxEffectsSetupFn} setupFn
* @returns RxEffects
*
* @docsCategory RxEffects
* @docsPage RxEffects
*
*/
export declare function rxEffects(setupFn?: RxEffectsSetupFn): RxEffects;
export {};
//# sourceMappingURL=rx-effects.d.ts.map