-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathmemberListStore.tsx
More file actions
73 lines (59 loc) · 1.44 KB
/
memberListStore.tsx
File metadata and controls
73 lines (59 loc) · 1.44 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import Reflux from 'reflux';
import {User} from 'app/types';
type MemberListStoreInterface = {
state: User[];
loaded: boolean;
loadInitialData(items: User[]): void;
isLoaded(): boolean;
getById(id: string): User | undefined;
getByEmail(email: string): User | undefined;
getAll(): User[];
};
const storeConfig: Reflux.StoreDefinition & MemberListStoreInterface = {
// listenables: MemberActions,
loaded: false,
state: [],
init() {
this.state = [];
this.loaded = false;
},
// TODO(dcramer): this should actually come from an action of some sorts
loadInitialData(items: User[]) {
this.state = items;
this.loaded = true;
this.trigger(this.state, 'initial');
},
isLoaded() {
return this.loaded;
},
getById(id) {
if (!this.state) {
return undefined;
}
id = '' + id;
for (let i = 0; i < this.state.length; i++) {
if (this.state[i].id === id) {
return this.state[i];
}
}
return undefined;
},
getByEmail(email) {
if (!this.state) {
return undefined;
}
email = email.toLowerCase();
for (let i = 0; i < this.state.length; i++) {
if (this.state[i].email.toLowerCase() === email) {
return this.state[i];
}
}
return undefined;
},
getAll() {
return this.state;
},
};
const MemberListStore = Reflux.createStore(storeConfig) as Reflux.Store &
MemberListStoreInterface;
export default MemberListStore;