-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (26 loc) · 842 Bytes
/
index.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
import {on, stream, scan} from 'flyd'
import {initialState, reducer} from 'store'
import {compose, filter, map} from 'ramda'
import localStorage from 'effects/localStorage'
import log from 'effects/log'
import resize from 'effects/resize'
import seed from 'effects/seed'
import setup from 'effects/setup'
import view from 'effects/view'
const push = stream()
const store = scan(reducer, initialState, push)
const effects = [localStorage, log, resize, seed, setup, view]
const deduplicatedStore = stream()
let prevState
on((nextState) => {
prevState !== nextState && deduplicatedStore(nextState)
prevState = nextState
}, store)
const listeners = compose(
filter((listener) => listener != null),
map((effect) => effect(push)),
)(effects)
on(
(state) => listeners.forEach((listener) => listener(state)),
deduplicatedStore
)