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
74 lines (60 loc) · 2.46 KB
/
actions.ts
File metadata and controls
74 lines (60 loc) · 2.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { Action } from '../app'
import * as mutations from './mutations'
import * as operations from './operations'
import { Message, Tab } from './state'
const onMessage: Action<Message> = (action) =>
action<Message>()
.mutation(mutations.performMutationsByMessageType)
.mutation(mutations.addMessagesFromClient)
export const loadDevtools: Action = (action) =>
action()
// .do(({ storage }) => storage.clear())
// Do a check if the current app matches the keys of the ???
.map(operations.getAppsFromStorage)
.mutation(mutations.setApps)
.map(operations.getCurrentPortFromStorage)
.mutation(mutations.setCurrentPort)
.mutation(mutations.setAppLoaded)
.do(operations.connectCurrentPort(onMessage(action)))
export const setError: Action<string> = (action) =>
action<string>().mutation(mutations.setError)
export const changeNewPortValue: Action<string> = (action) =>
action<string>()
.map(operations.toNumber)
.mutation(mutations.setNewPortValue)
export const addPort: Action = (action) =>
action()
.map(operations.getNewPortFromState)
.mutation(mutations.setCurrentPort)
.mutation(mutations.addNewApp)
.mutation(mutations.resetNewPortValue)
.do(operations.storeApps)
.do(operations.connectCurrentPort(onMessage))
export const changeTab: Action<Tab> = (action) =>
action<Tab>().mutation(mutations.changeTab)
export const toggleExpandState: Action<string[]> = (action) =>
action<string[]>().mutation(mutations.toggleExpandStatePath)
export const selectAction: Action<string> = (action) =>
action<string>()
.mutation(mutations.toggleActionItemCollapse)
.mutation(mutations.selectAction)
type Collapsed = {
isCollapsed: boolean
}
export const toggleCollapsed: Action<Collapsed> = (action) =>
action<Collapsed>().mutation(mutations.toggleCollapsed)
export const configurePort: Action = (action) =>
action().mutation(mutations.configurePort)
export const cancelConfigurePort: Action = (action) =>
action().mutation(mutations.cancelConfigurePort)
export const removeApp: Action = (action) =>
action()
.filter(operations.confirm('Are you sure you want to remove the app?'))
.do(operations.removeCurrentPort)
.mutation(mutations.removeApp)
.do(operations.storeApps)
.do(operations.connectCurrentPort(onMessage(action)))
export const selectPort: Action<string> = (action) =>
action<string>()
.mutation(mutations.selectPort)
.do(operations.connectCurrentPort(onMessage(action)))