UNPKG

1.32 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports.pagesReducer = void 0;
5const pagesReducer = (state = new Map(), action) => {
6 switch (action.type) {
7 case `DELETE_CACHE`:
8 return new Map();
9 case `CREATE_PAGE`:
10 {
11 var _action$plugin;
12 // throws an error if the page is not created by a plugin
13 if (!((_action$plugin = action.plugin) !== null && _action$plugin !== void 0 && _action$plugin.name)) {
14 console.log(``);
15 console.error(JSON.stringify(action, null, 4));
16 console.log(``);
17 throw new Error(`Pages can only be created by plugins. There wasn't a plugin set when creating this page.`);
18 }
19
20 // Add page to the state with the path as key
21 state.set(action.payload.path, action.payload);
22 return state;
23 }
24 case `DELETE_PAGE`:
25 {
26 state.delete(action.payload.path);
27 return state;
28 }
29 case `MATERIALIZE_PAGE_MODE`:
30 {
31 const page = state.get(action.payload.path);
32 if (!page) {
33 throw new Error(`Could not find page by path: ${action.payload.path}`);
34 }
35 page.mode = action.payload.pageMode;
36 return state;
37 }
38 default:
39 return state;
40 }
41};
42exports.pagesReducer = pagesReducer;
43//# sourceMappingURL=pages.js.map
\No newline at end of file