forked from angular-redux/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage.ts
40 lines (33 loc) · 1.08 KB
/
page.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { select, select$ } from '@angular-redux/store';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { pipe, prop, sortBy, values } from 'ramda';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { AnimalAPIActions } from '../animals/api/actions';
import { Animal, ANIMAL_TYPES } from '../animals/model';
export function sortAnimals(animalDictionary$: Observable<{}>) {
return animalDictionary$.pipe(
map(
pipe(
values,
sortBy(prop('name')),
),
),
);
}
@Component({
templateUrl: './page.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ElephantPageComponent {
// Get elephant-related data out of the Redux store as observables.
@select$(['elephant', 'items'], sortAnimals)
readonly animals!: Observable<Animal[]>;
@select(['elephant', 'loading'])
readonly loading!: Observable<boolean>;
@select(['elephant', 'error'])
readonly error!: Observable<boolean>;
constructor(actions: AnimalAPIActions) {
actions.loadAnimals(ANIMAL_TYPES.ELEPHANT);
}
}