You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Angular integration for Nano Stores, a tiny state manager
with many atomic tree-shakable stores.
How to install
pnpm add @nanostores/angular # or npm or yarn
How to use
// your NgModule:import{NANOSTORES,NanostoresService}from'@nanostores/angular';
@NgModule({providers: [{provide: NANOSTORES,useClass: NanostoresService}], ... })
app.component.ts:
// example using async pipes:import{Component}from'@angular/core';import{NanostoresService}from'@nanostores/angular';import{Observable,switchMap}from'rxjs';import{profile}from'../stores/profile';import{IUser,User}from'../stores/user';
@Component({selector: "app-root",template: '<p *ngIf="(currentUser$ | async) as user">{{ user.name }}</p>'})exportclassAppComponent{currentUser$: Observable<IUser>=this.nanostores.useStore(profile).pipe(switchMap(userId=>this.nanostores.useStore(User(userId))));constructor(privatenanostores: NanostoresService){}}
// example without async pipes:import{Component,OnInit}from'@angular/core';import{NanostoresService}from'@nanostores/angular';import{switchMap}from'rxjs';import{profile}from'../stores/profile';import{User}from'../stores/user';
@Component({selector: "app-root",template: '<p>{{ text }}</p>'})exportclassAppComponentimplementsOnInit{text='';constructor(privatenanostores: NanostoresService){}ngOnInit(){this.nanostores.useStore(profile).pipe(switchMap((userId: string)=>this.nanostores.useStore(User(userId)))).subscribe(user=>this.text=`User name is ${user.name}`);}}
About
Angular integration for Nano Stores, a tiny state manager with many atomic tree-shakable stores.