-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathactions.ts
48 lines (42 loc) · 1.31 KB
/
actions.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
41
42
43
44
45
46
47
48
import { dispatch } from '@angular-redux/store';
import { Injectable } from '@angular/core';
import { FluxStandardAction } from 'flux-standard-action';
import { Animal, AnimalType } from '../model';
// Flux-standard-action gives us stronger typing of our actions.
type Payload = Animal[];
interface MetaData {
animalType: AnimalType;
}
export type AnimalAPIAction = FluxStandardAction<Payload, MetaData>;
@Injectable()
export class AnimalAPIActions {
static readonly LOAD_ANIMALS = 'LOAD_ANIMALS';
static readonly LOAD_STARTED = 'LOAD_STARTED';
static readonly LOAD_SUCCEEDED = 'LOAD_SUCCEEDED';
static readonly LOAD_FAILED = 'LOAD_FAILED';
@dispatch()
loadAnimals = (animalType: AnimalType): AnimalAPIAction => ({
type: AnimalAPIActions.LOAD_ANIMALS,
meta: { animalType },
payload: null,
});
loadStarted = (animalType: AnimalType): AnimalAPIAction => ({
type: AnimalAPIActions.LOAD_STARTED,
meta: { animalType },
payload: null,
});
loadSucceeded = (
animalType: AnimalType,
payload: Payload,
): AnimalAPIAction => ({
type: AnimalAPIActions.LOAD_SUCCEEDED,
meta: { animalType },
payload,
});
loadFailed = (animalType: AnimalType, error): AnimalAPIAction => ({
type: AnimalAPIActions.LOAD_FAILED,
meta: { animalType },
payload: null,
error,
});
}