-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
status.ts
52 lines (50 loc) · 1.28 KB
/
status.ts
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
import _ from "lodash"
import { ActionsUnion, IGatsbyState } from "../types"
const defaultState: IGatsbyState["status"] = {
PLUGINS_HASH: ``,
LAST_NODE_COUNTER: 0,
plugins: {},
}
export const statusReducer = (
state: IGatsbyState["status"] = defaultState,
action: ActionsUnion
): IGatsbyState["status"] => {
switch (action.type) {
case `DELETE_CACHE`:
return defaultState
case `UPDATE_PLUGINS_HASH`:
return {
...state,
PLUGINS_HASH: action.payload,
}
case `SET_PLUGIN_STATUS`:
if (!action.plugin || !action.plugin?.name) {
throw new Error(`You can't set plugin status without a plugin`)
}
if (!_.isObject(action.payload)) {
throw new Error(
`You must pass an object into setPluginStatus. What was passed in was ${JSON.stringify(
action.payload,
null,
4
)}`
)
}
return {
...state,
plugins: {
...state.plugins,
[action.plugin.name]: _.merge(
{},
state.plugins[action.plugin.name],
action.payload
),
},
}
case `CREATE_NODE`:
state.LAST_NODE_COUNTER = action.payload.internal.counter
return state
default:
return state
}
}