forked from cerebral/overmind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
71 lines (63 loc) · 1.55 KB
/
utils.ts
File metadata and controls
71 lines (63 loc) · 1.55 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
import * as ColorHash from 'color-hash'
import { App } from './state'
export const runMutation = (state) => (mutation) => {
const pathArray = mutation.path.split('.')
const key = pathArray.pop()
const target = pathArray.reduce((current, pathKey) => current[pathKey], state)
switch (mutation.method) {
case 'set':
target[key] = mutation.args[0]
break
case 'unset':
delete target[key]
break
default:
target[key][mutation.method](...mutation.args)
}
}
export const getActionId = (details: {
actionId: number
executionId: number
}) => `${details.actionId}_${details.executionId}`
export const getOperatorId = (details: {
actionId: number
executionId: number
operatorId: number
}) => `${getActionId(details)}_${details.operatorId}`
export const createApp = (data: Partial<App>): App =>
Object.assign(
{
name: null,
port: null,
messages: [],
state: {},
components: {},
derived: {},
computed: {},
flushes: {},
actions: {},
actionsList: [],
currentActionId: null,
flushByActionId: {},
flushByOperatorId: {},
},
data
)
export const nameToColor = (name, lightness = 0.5, saturation = 0.5) => {
let colorHash = new ColorHash({
saturation: saturation,
lightness: lightness,
})
return colorHash.hex(name)
}
export const ensureFlushExists = (flushes, flushId) => {
if (!flushes[flushId]) {
flushes[flushId] = {
flushId,
mutations: [],
components: [],
derived: [],
computed: [],
}
}
}