-
-
Notifications
You must be signed in to change notification settings - Fork 310
/
index.ts
64 lines (55 loc) · 2.08 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
63
64
import { combineReducers, Action, ActionReducer, ActionReducerMap, MetaReducer } from '@ngrx/store';
import { compose } from '@ngrx/store';
import { localStorageSync } from 'ngrx-store-localstorage';
import { environment } from '../../environments/environment';
import * as fromLayout from './layout/layout';
import * as fromQuery from './query/query';
import * as fromHeaders from './headers/headers';
import * as fromVariables from './variables/variables';
import * as fromDialogs from './dialogs/dialogs';
import * as fromGqlSchema from './gql-schema/gql-schema';
import * as fromDocs from './docs/docs';
import * as fromWindows from './windows';
import * as fromHistory from './history/history';
import * as fromWindowsMeta from './windows-meta/windows-meta';
export interface PerWindowState {
layout: fromLayout.State;
query: fromQuery.State;
headers: fromHeaders.State;
variables: fromVariables.State;
dialogs: fromDialogs.State;
schema: fromGqlSchema.State;
docs: fromDocs.State;
history: fromHistory.State;
windowId: string; // Used by the window reducer
}
const perWindowReducers = {
layout: fromLayout.layoutReducer,
query: fromQuery.queryReducer,
headers: fromHeaders.headerReducer,
variables: fromVariables.variableReducer,
dialogs: fromDialogs.dialogReducer,
schema: fromGqlSchema.gqlSchemaReducer,
docs: fromDocs.docsReducer,
history: fromHistory.historyReducer
};
export interface State {
windows: fromWindows.State;
windowsMeta: fromWindowsMeta.State;
}
// Meta reducer to log actions
export const log = (_reducer) => (state: State, action: Action) => {
if (!environment.production) {
console.log(action.type, action);
}
return _reducer(state, action);
};
export const keySerializer = (key) => 'altair_' + key;
export const metaReducers: MetaReducer<any>[] = [
localStorageSync({ keys: ['windows', 'windowsMeta'], rehydrate: true, storageKeySerializer: keySerializer }),
log
];
export const reducer: ActionReducerMap<State> = {
windows: fromWindows.windows(combineReducers(perWindowReducers)),
windowsMeta: fromWindowsMeta.windowsMetaReducer
};