-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
actions.js
99 lines (86 loc) · 2.08 KB
/
actions.js
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
/* @flow */
import type {
ResetSimulationAction,
LoadPreviousSimulationAction,
StepAction,
DeletePreviousSimulationAction,
SetSimulationConfigAction,
SetSituationBranchAction
} from 'Types/ActionsTypes'
import { deletePersistedSimulation } from '../storage/persistSimulation'
import type { Thunk } from 'Types/ActionsTypes'
export const resetSimulation = () => (dispatch: any => void): void => {
dispatch(
({
type: 'RESET_SIMULATION'
}: ResetSimulationAction)
)
}
export const goToQuestion = (question: string): StepAction => ({
type: 'STEP_ACTION',
name: 'unfold',
step: question
})
export const validateStepWithValue = (
dottedName,
value: any
): Thunk<StepAction> => dispatch => {
dispatch(updateSituation(dottedName, value))
dispatch({
type: 'STEP_ACTION',
name: 'fold',
step: dottedName
})
}
export const setSituationBranch = (id: number): SetSituationBranchAction => ({
type: 'SET_SITUATION_BRANCH',
id
})
export const setSimulationConfig = (
config: Object
): Thunk<SetSimulationConfigAction> => (dispatch, _, { history }): void => {
const url = history.location.pathname
dispatch({
type: 'SET_SIMULATION',
url,
config
})
}
export const deletePreviousSimulation = () => (
dispatch: DeletePreviousSimulationAction => void
) => {
dispatch({
type: 'DELETE_PREVIOUS_SIMULATION'
})
deletePersistedSimulation()
}
export const updateSituation = (fieldName, value) => ({
type: 'UPDATE_SITUATION',
fieldName,
value
})
export const updatePeriod = toPeriod => ({
type: 'UPDATE_PERIOD',
toPeriod
})
// $FlowFixMe
export function setExample(name, situation, dottedName) {
return { type: 'SET_EXAMPLE', name, situation, dottedName }
}
export const goBackToSimulation = (): Thunk<any> => (
dispatch,
getState,
{ history }
) => {
dispatch({ type: 'SET_EXEMPLE', name: null })
history.push(getState().simulation.url)
}
export function loadPreviousSimulation(): LoadPreviousSimulationAction {
return {
type: 'LOAD_PREVIOUS_SIMULATION'
}
}
export function hideControl(id: string) {
return { type: 'HIDE_CONTROL', id }
}
export const EXPLAIN_VARIABLE = 'EXPLAIN_VARIABLE'