-
-
Notifications
You must be signed in to change notification settings - Fork 190
/
issue427.ts
44 lines (39 loc) · 962 Bytes
/
issue427.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
import { Computed, computed } from 'easy-peasy';
interface AppModel {
currentRoleId?: number;
}
interface Role {
id: number;
name: string;
description: string;
}
interface RolesModel {
rolesMap: { [roleId: string]: Role };
currentRole: Computed<RolesModel, Role | undefined, StoreModel>;
currentRoleName: Computed<RolesModel, string | undefined, StoreModel>;
}
interface StoreModel {
app: AppModel;
roles: RolesModel;
}
const storeModel: StoreModel = {
app: {
currentRoleId: 1,
},
roles: {
rolesMap: {
'1': { id: 1, name: 'Role example', description: 'Role description' },
},
currentRole: computed(
[
(_, storeState) => storeState.app.currentRoleId,
(state) => state.rolesMap,
],
(roleId, rolesMap) => (roleId != null ? rolesMap[roleId] : undefined),
),
currentRoleName: computed(
[(state) => state.currentRole],
(role) => role && role.name,
),
},
};