1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | exports.__esModule = true;
|
5 | exports.componentsReducer = void 0;
|
6 | var _normalizePath = _interopRequireDefault(require("../../utils/normalize-path"));
|
7 | let programStatus = `BOOTSTRAPPING`;
|
8 |
|
9 |
|
10 |
|
11 | const componentsReducer = (state = new Map(), action) => {
|
12 | switch (action.type) {
|
13 | case `CREATE_SLICE`:
|
14 | {
|
15 | let component = state.get(action.payload.componentPath);
|
16 | if (!component) {
|
17 | component = {
|
18 | componentPath: action.payload.componentPath,
|
19 | componentChunkName: action.payload.componentChunkName,
|
20 | query: ``,
|
21 | pages: new Set(),
|
22 | isInBootstrap: true,
|
23 | serverData: false,
|
24 | config: false,
|
25 | isSlice: true,
|
26 | Head: false
|
27 | };
|
28 | }
|
29 | component.pages.add(action.payload.name);
|
30 | component.isInBootstrap = programStatus === `BOOTSTRAPPING`;
|
31 | state.set(action.payload.componentPath, component);
|
32 | return state;
|
33 | }
|
34 | case `DELETE_CACHE`:
|
35 | return new Map();
|
36 | case `SET_PROGRAM_STATUS`:
|
37 | programStatus = action.payload;
|
38 | return state;
|
39 | case `CREATE_PAGE`:
|
40 | {
|
41 |
|
42 | let component = state.get(action.payload.componentPath);
|
43 | if (!component) {
|
44 | component = {
|
45 | componentPath: action.payload.componentPath,
|
46 | componentChunkName: action.payload.componentChunkName,
|
47 | query: ``,
|
48 | pages: new Set(),
|
49 | isInBootstrap: true,
|
50 | serverData: false,
|
51 | config: false,
|
52 | isSlice: false,
|
53 | Head: false
|
54 | };
|
55 | }
|
56 | component.pages.add(action.payload.path);
|
57 | component.isInBootstrap = programStatus === `BOOTSTRAPPING`;
|
58 | state.set(action.payload.componentPath, component);
|
59 | return state;
|
60 | }
|
61 | case `QUERY_EXTRACTED`:
|
62 | {
|
63 | action.payload.componentPath = (0, _normalizePath.default)(action.payload.componentPath);
|
64 | const component = state.get(action.payload.componentPath);
|
65 | component.query = action.payload.query;
|
66 | state.set(action.payload.componentPath, component);
|
67 | return state;
|
68 | }
|
69 | case `REMOVE_STATIC_QUERIES_BY_TEMPLATE`:
|
70 | {
|
71 | action.payload.componentPath = (0, _normalizePath.default)(action.payload.componentPath);
|
72 | state.delete(action.payload.componentPath);
|
73 | return state;
|
74 | }
|
75 | case `SET_COMPONENT_FEATURES`:
|
76 | {
|
77 | const path = (0, _normalizePath.default)(action.payload.componentPath);
|
78 | const component = state.get(path);
|
79 | if (component) {
|
80 | component.serverData = action.payload.serverData;
|
81 | component.config = action.payload.config;
|
82 | component.Head = action.payload.Head;
|
83 | }
|
84 | return state;
|
85 | }
|
86 | case `DELETE_PAGE`:
|
87 | {
|
88 | const component = state.get((0, _normalizePath.default)(action.payload.component));
|
89 | component.pages.delete(action.payload.path);
|
90 | return state;
|
91 | }
|
92 | case `DELETE_SLICE`:
|
93 | {
|
94 | const component = state.get((0, _normalizePath.default)(action.payload.componentPath));
|
95 | if (component) {
|
96 | component.pages.delete(action.payload.name);
|
97 | }
|
98 | return state;
|
99 | }
|
100 | }
|
101 | return state;
|
102 | };
|
103 | exports.componentsReducer = componentsReducer;
|
104 |
|
\ | No newline at end of file |