Created
December 22, 2022 21:20
-
-
Save ssougnez/6808c195119a30891c31c0df00ca1138 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NgFor } from '@angular/common'; | |
import { ChangeDetectionStrategy, Component, inject, TrackByFunction } from '@angular/core'; | |
import { NgStore, NgStoreModule, trackByValue } from '@ssougnez/ng-store'; | |
import { map, Observable } from 'rxjs'; | |
import { Pokemon } from './models/pokemon.model'; | |
import { PokemonService } from './services/pokemon.service'; | |
import { AppState } from './state/app.state'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.scss'], | |
changeDetection: ChangeDetectionStrategy.OnPush, | |
standalone: true, | |
imports: [ | |
NgFor, | |
NgStoreModule | |
] | |
}) | |
export class AppComponent { | |
private readonly _pokemonService = inject(PokemonService); | |
private readonly _store: NgStore<AppState> = inject(NgStore); | |
public query$: Observable<Pokemon[]> = this._pokemonService.loadPokemons(); | |
public pokemons$: Observable<Pokemon[]> = this._store.selectValues<Pokemon>(s => s.pokemons); | |
public trackByValue: TrackByFunction<Pokemon> = trackByValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment