forked from cerebral/overmind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.ts
More file actions
102 lines (80 loc) · 2.54 KB
/
state.ts
File metadata and controls
102 lines (80 loc) · 2.54 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { Derive } from './'
import {
Action,
App,
Apps,
Component,
Flush,
GroupedComponents,
Tab,
} from './types'
export let isConnecting: boolean = true
export let error: string = null
export let currentAppName: string = null
export let port: string = '3031'
export let apps: Apps = {}
export let newPortValue: string = ''
export let currentTab: Tab = Tab.State
export let expandedStatePaths: string[] = ['']
export const currentApp: Derive<App> = (state) =>
state.apps[state.currentAppName]
export const componentsMounted: Derive<Component[]> = (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: Derive<number> = (state) =>
state.componentsMounted.reduce(
(aggr, component) => aggr + component.updateCount,
0
)
export const componentsStatePathCount: Derive<number> = (state) =>
state.componentsMounted.reduce(
(aggr, component) => aggr + component.paths.length,
0
)
export const flushes: Derive<Flush[]> = (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: Derive<number> = (state) =>
state.flushes.reduce((aggr, flush) => aggr + flush.mutations.length, 0)
export const flushesStatePathCount: Derive<number> = (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: Derive<Action> = (state) =>
state.currentApp.actions[state.currentApp.currentActionId]
export let expandAllActionDetails: boolean = false
export const expandedComponents: string[] = []
export const groupedComponents: Derive<GroupedComponents> = (state) => {
const components = state.componentsMounted
return components.reduce(
(aggr, component) => {
if (aggr[component.name]) {
aggr[component.name].components.push(component)
} else {
aggr[component.name] = {
name: component.name,
components: [component],
isCollapsed: !state.expandedComponents.includes(component.name),
}
}
return aggr
},
{} as GroupedComponents
)
}