Caching
import { State, Action, StateContext } from '@ngxs/store';
import { tap } from 'rxjs/operators';
export class GetNovels {
static readonly type = '[Novels] Get novels';
}
@State<Novel[]>({
name: 'novels',
defaults: []
})
export class NovelsState {
constructor(private novelsService: NovelsService) {}
@Action(GetNovels)
getNovels(ctx: StateContext<Novel[]>) {
return this.novelsService.getNovels().pipe(tap(novels => ctx.setState(novels)));
}
}Last updated

