UNPKG

@nanostores/angular

Version:

Angular integration for Nano Stores, a tiny state manager with many atomic tree-shakable stores

46 lines (40 loc) 1.66 kB
import * as i0 from '@angular/core'; import { Injectable, InjectionToken } from '@angular/core'; import { ReplaySubject, Observable } from 'rxjs'; import { distinctUntilChanged, takeUntil } from 'rxjs/operators'; class NanostoresService { constructor() { this.destroyed$ = new ReplaySubject(1); } /** * @param store Store instance. * @returns Observable that contains current Store value. */ useStore(store) { return new Observable((sub) => { sub.next(store.get()); return store.subscribe((value) => sub.next(value)); }).pipe(distinctUntilChanged(), takeUntil(this.destroyed$)); } ngOnDestroy() { this.destroyed$.next(); this.destroyed$.complete(); } /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NanostoresService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); } /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NanostoresService, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: NanostoresService, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }] }); const NANOSTORES = new InjectionToken('nanostores Injection Token'); /* * Public API Surface of @nanostores/angular */ /** * Generated bundle index. Do not edit. */ export { NANOSTORES, NanostoresService }; //# sourceMappingURL=nanostores-angular.mjs.map