-
Notifications
You must be signed in to change notification settings - Fork 1
/
state.js
38 lines (26 loc) · 933 Bytes
/
state.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
/* @flow */
import { Map, OrderedSet, Record } from 'immutable';
import type { PostsIndex, PostsMap } from './entity';
type LeafStateShape = {|
index: PostsIndex,
entities: PostsMap,
|};
export type LeafState = Record<LeafStateShape>;
const State = Record({
index: new OrderedSet(),
entities: new Map(),
});
// export default new State();
// I'm cheatting a bit as in the real world data must be fetched or rehydrated,
// but I'm normalizing and putting it in the store right here.
// See `async-interactions` example for details.
import { normalize } from 'normalizr';
import * as schema from '../schema';
import { normalizeEntities } from '../../../utils';
import { posts } from '../../../api/data';
import { Post } from './entity';
const { result, entities } = normalize(posts, schema.posts);
export default new State({
index: new OrderedSet(result),
entities: normalizeEntities(entities.posts, Post),
});