2019-09-18 06:02:21 +00:00
|
|
|
import { Type, InjectionToken } from '@angular/core';
|
|
|
|
|
|
|
|
import {
|
|
|
|
ActionReducer,
|
|
|
|
MetaReducer,
|
|
|
|
Action,
|
|
|
|
ActionReducerMap
|
|
|
|
} from '@ngrx/store';
|
|
|
|
import * as fromRouter from '@ngrx/router-store';
|
|
|
|
import { storeFreeze } from 'ngrx-store-freeze';
|
|
|
|
|
|
|
|
import { environment } from '../../environments/environment';
|
|
|
|
|
|
|
|
import * as AccountStore from './account';
|
2019-09-25 08:26:19 +00:00
|
|
|
import * as MessengerStore from './messenger';
|
2019-09-19 01:40:16 +00:00
|
|
|
import * as SettingStore from './setting';
|
2019-09-18 06:02:21 +00:00
|
|
|
|
|
|
|
export interface State {
|
|
|
|
router: fromRouter.RouterReducerState<any>;
|
|
|
|
account: AccountStore.State;
|
2019-09-25 08:26:19 +00:00
|
|
|
messenger: MessengerStore.State;
|
2019-09-19 01:40:16 +00:00
|
|
|
setting: SettingStore.State;
|
2019-09-18 06:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Our state is composed of a map of action reducer functions.
|
|
|
|
* These reducer functions are called with each dispatched action
|
|
|
|
* and the current or initial state and return a new immutable state.
|
|
|
|
*/
|
|
|
|
export const ROOT_REDUCERS = new InjectionToken<
|
|
|
|
ActionReducerMap<State, Action>
|
|
|
|
>('Root reducers token', {
|
|
|
|
factory: () => ({
|
|
|
|
router: fromRouter.routerReducer,
|
2019-09-19 01:40:16 +00:00
|
|
|
account: AccountStore.reducers,
|
2019-09-25 08:26:19 +00:00
|
|
|
messenger: MessengerStore.reducers,
|
2019-09-19 01:40:16 +00:00
|
|
|
setting: SettingStore.reducers
|
2019-09-18 06:02:21 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2019-09-19 01:40:16 +00:00
|
|
|
export const effects: Type<any>[] = [
|
|
|
|
...AccountStore.effects,
|
2019-09-25 08:26:19 +00:00
|
|
|
...MessengerStore.effects,
|
2019-09-19 01:40:16 +00:00
|
|
|
...SettingStore.effects
|
|
|
|
];
|
2019-09-18 06:02:21 +00:00
|
|
|
|
|
|
|
export function logger(reducer: ActionReducer<State>): ActionReducer<State> {
|
|
|
|
return (state, action) => {
|
|
|
|
const result = reducer(state, action);
|
|
|
|
console.groupCollapsed(action.type);
|
|
|
|
console.log('prev state', state);
|
|
|
|
console.log('action', action);
|
|
|
|
console.log('next state', result);
|
|
|
|
console.groupEnd();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export const metaReducers: MetaReducer<State>[] = !environment.production
|
|
|
|
? [logger, storeFreeze]
|
|
|
|
: [];
|
|
|
|
|
|
|
|
export const AccountSelector = AccountStore.selectors(
|
|
|
|
(state: State) => state.account
|
|
|
|
);
|
2019-09-19 01:40:16 +00:00
|
|
|
|
2019-09-25 08:26:19 +00:00
|
|
|
export const MessengerSelector = MessengerStore.selectors(
|
|
|
|
(state: State) => state.messenger
|
|
|
|
);
|
|
|
|
|
2019-09-19 01:40:16 +00:00
|
|
|
export const SettingSelector = SettingStore.selectors(
|
|
|
|
(state: State) => state.setting
|
|
|
|
);
|