forked from cerebral/overmind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactions.ts
More file actions
67 lines (52 loc) · 2.16 KB
/
actions.ts
File metadata and controls
67 lines (52 loc) · 2.16 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
import { Action } from './'
import * as mutations from './mutations'
import * as operations from './operations'
import { GroupedComponent, Message, Tab } from './types'
const handleClientMessages: Action<Message> = (action) =>
action
.mutate(mutations.ensureCurrentApp)
.mutate(mutations.performMutationsByMessageType)
.mutate(mutations.addMessagesFromClient)
const setPortExists: Action<Message> = (action) =>
action.mutate(mutations.setPortExists)
const onMessage: Action<Message> = (action) =>
action.when(operations.isPortExistsMessage, {
true: setPortExists,
false: handleClientMessages,
})
export const loadDevtools: Action = (action) =>
action
// .run(({ storage }) => storage.clear())
.map(operations.getCurrentPortFromStorage)
.mutate(mutations.setPort)
.run(operations.connectCurrentPort(onMessage(action as any)))
export const setError: Action<string> = ({ mutate }) =>
mutate(mutations.setError)
export const changeNewPortValue: Action<string> = (action) =>
action.map(operations.toNumber).mutate(mutations.setNewPortValue)
export const addConnection: Action = (action) =>
action
.mutate(mutations.setConnecting)
.map(operations.getNewPortFromState)
.mutate(mutations.setPort)
.mutate(mutations.resetNewPortValue)
.run(operations.connectCurrentPort(onMessage))
export const changeTab: Action<Tab> = ({ mutate }) =>
mutate(mutations.changeTab)
export const toggleExpandState: Action<string[]> = ({ mutate }) =>
mutate(mutations.toggleExpandStatePath)
export const selectAction: Action<string> = ({ mutate }) =>
mutate(mutations.toggleActionItemCollapse).mutate(mutations.selectAction)
type Collapsed = {
isCollapsed: boolean
}
export const toggleCollapsedActionItem: Action<Collapsed> = (action) =>
action
.filter(operations.isNotExpandingAllActions)
.mutate(mutations.toggleCollapsed)
export const toggleGroupedComponent: Action<string> = (action) =>
action.mutate(mutations.toggleGroupedComponent)
export const selectApp: Action<string> = (action) =>
action.mutate(mutations.selectApp)
export const toggleExpandAllActions: Action = ({ mutate }) =>
mutate(mutations.toggleExpandAllActions)