This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const developmentReducer: ActionReducer<IAppState> = compose(storeFreeze, combineReducers)(reducers); | |
| const productionReducer: ActionReducer<IAppState> = combineReducers(reducers); | |
| // our meta-reducer will take care of forwarding all actions | |
| export function AppReducer(state: any, action: any) { | |
| if (String('<%= BUILD_TYPE %>') === 'dev') { | |
| return developmentReducer(state, action); | |
| } else { | |
| return productionReducer(state, action); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Application state is like a database. | |
| // Currently our 'database' comprises of a single table | |
| // that can be modified by a certain reducer. | |
| // The sub-state's name in IAppState corresponds to | |
| // reducer's name in reducers object. | |
| export interface IAppState { | |
| customerState: fromSubstates.ICustomerState | |
| }; | |
| // and we have only a single reducer here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return (<any>Object).assign({}, state, { | |
| customer: action.payload | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { ICustomerState, initialCustomerState } from '../states/sub-states'; | |
| import { CustomerAction, CustomerActionTypes } from '../actions'; | |
| export function customerReducer( | |
| state: ICustomerState = initialCustomerState, | |
| action: CustomerAction | |
| ): ICustomerState { | |
| switch (action.type) { | |
| case CustomerActionTypes.INITIALIZED: | |
| return (<any>Object).assign({}, state, { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Injectable } from '@angular/core'; | |
| import { Action } from '@ngrx/store'; | |
| import { ICustomer } from '../../interfaces'; | |
| import * as customer from '../customer.actions'; | |
| @Injectable() | |
| export class CustomerActions { | |
| public customerInit() { | |
| return new customer.InitCustomerAction(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export type CustomerAction | |
| = InitCustomerAction | |
| | InitializedCustomerAction | |
| | InitFailedCustomerAction | |
| | CustomerSelectedAction | |
| | CustomerChangedAction | |
| | CustomerDeletedAction | |
| | CustomerSavedAction; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class InitCustomerAction implements Action { | |
| type = CustomerActionTypes.INIT; | |
| payload: ICustomer = null; | |
| } | |
| export class InitializedCustomerAction implements Action { | |
| type = CustomerActionTypes.INITIALIZED; | |
| constructor(public payload: ICustomer) { } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export interface ICustomerActions { | |
| INIT: string; | |
| INIT_FAILED: string; | |
| INITIALIZED: string; | |
| SELECTED: string; | |
| CHANGED: string; | |
| SAVED: string; | |
| DELETED: string; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const appStore = provideStore( | |
| { | |
| vrModule: vrModuleReducer | |
| }, | |
| { | |
| vrModule: this.vrModule | |
| } | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Initialize subscriptions and get app state via @ngrx (Redux implementation for Angular2) | |
| */ | |
| public ngOnInit() { | |
| [....snip...] | |
| this.availableModules = <Observable<IVrModule[]>> this.store.select('vrModule'); | |
| [....snip...] | |
| } |