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
62 lines (53 loc) · 1.6 KB
/
derived.ts
File metadata and controls
62 lines (53 loc) · 1.6 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
import { derived } from 'overmind'
import { State, Component } from './state'
export const currentApp = derived(
(state: State) => state.apps[state.currentPort]
)
export const componentsMounted = derived((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 = derived((state: State) =>
state.componentsMounted.reduce(
(aggr, component) => aggr + component.updateCount,
0
)
)
export const componentsStatePathCount = derived((state: State) =>
state.componentsMounted.reduce(
(aggr, component) => aggr + component.paths.length,
0
)
)
export const flushes = derived((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 = derived((state: State) =>
state.flushes.reduce((aggr, flush) => aggr + flush.mutations.length, 0)
)
export const flushesStatePathCount = derived(
(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 = derived(
(state: State) => state.currentApp.actions[state.currentApp.currentActionId]
)