forked from gpbl/isomorphic500
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FeaturedStore.js
52 lines (41 loc) · 1.11 KB
/
FeaturedStore.js
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
import { BaseStore } from "fluxible/addons";
import Actions from "../constants/Actions";
/*
This is a "list store", i.e. it holds only ids referring to another
"resource store". This one keeps the `id` of the photos in PhotoStore
when the featured photos has been loaded.
*/
export default class FeaturedStore extends BaseStore {
static storeName = "FeaturedStore"
static handlers = {
[Actions.LOAD_FEATURED_PHOTOS_SUCCESS]: "handleLoadSuccess"
}
constructor(dispatcher) {
super(dispatcher);
this.featured = [];
this.currentFeature = null;
}
handleLoadSuccess({ feature, photos }) {
this.dispatcher.waitFor("PhotoStore", () => {
this.currentFeature = feature;
this.featured = photos.map(photo => photo.id);
this.emitChange();
});
}
getFeaturedPhotos() {
return this.featured;
}
getCurrentFeature() {
return this.currentFeature;
}
dehydrate() {
return {
featured: this.featured,
currentFeature: this.currentFeature
};
}
rehydrate(state) {
this.featured = state.featured;
this.currentFeature = state.currentFeature;
}
}