forked from cerebral/overmind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathderived.ts
More file actions
51 lines (42 loc) · 1.46 KB
/
derived.ts
File metadata and controls
51 lines (42 loc) · 1.46 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
import { State, Component } from './state'
export const currentApp = (state: State) => state.apps[state.currentPort]
export const componentsMounted = (state: State) =>
Object.keys(state.currentApp.components).reduce(
(aggr, key) => {
if (state.currentApp.components[key].isMounted) {
return aggr.concat(state.currentApp.components[key])
}
return aggr
},
[] as Component[]
)
export const componentsUpdateCount = (state: State) =>
state.componentsMounted.reduce(
(aggr, component) => aggr + component.updateCount,
0
)
export const componentsStatePathCount = (state: State) =>
state.componentsMounted.reduce(
(aggr, component) => aggr + component.paths.length,
0
)
export const flushes = (state: State) =>
Object.keys(state.currentApp.flushes)
.sort(
(idA, idB) =>
state.currentApp.flushes[idB].flushId -
state.currentApp.flushes[idA].flushId
)
.map((id) => state.currentApp.flushes[id])
export const flushesMutationsCount = (state: State) =>
state.flushes.reduce((aggr, flush) => aggr + flush.mutations.length, 0)
export const flushesStatePathCount = (state: State) =>
state.flushes.reduce((aggr, flush) => {
return flush.mutations.reduce(
(aggr, mutation) =>
aggr.includes(mutation.path) ? aggr : aggr.concat(mutation.path),
aggr
)
}, []).length
export const currentAction = (state: State) =>
state.currentApp.actions[state.currentApp.currentActionId]