This file contains 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 { Action } from '@ngrx/store'; | |
import { MyModel } from '../../models'; | |
export enum ActionTypes { | |
LOAD_REQUEST = '[My Feature] Load Request', | |
LOAD_FAILURE = '[My Feature] Load Failure', | |
LOAD_SUCCESS = '[My Feature] Load Success' | |
} | |
export class LoadRequestAction implements Action { |
This file contains 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 { createEntityAdapter, EntityAdapter, EntityState } from '@ngrx/entity'; | |
import { MyModel } from '../../models'; | |
export const featureAdapter: EntityAdapter< | |
MyModel | |
> = createEntityAdapter<MyModel>({ | |
selectId: model => model.id, | |
sortComparer: (a: MyModel, b: MyModel): number => | |
b.someDate.toString().localeCompare(a.someDate.toString()) | |
}); |
This file contains 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 { User } from '../../models'; | |
export interface State { | |
user: User | null; | |
isLoading: boolean; | |
error: string; | |
} | |
export const initialState: State = { | |
user: null, |
This file contains 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 { Actions, ActionTypes } from './actions'; | |
import { featureAdapter, initialState, State } from './state'; | |
export function featureReducer(state = initialState, action: Actions): State { | |
switch (action.type) { | |
case ActionTypes.LOAD_REQUEST: { | |
return { | |
...state, | |
isLoading: true, | |
error: null |
This file contains 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 { Actions, ActionTypes } from './actions'; | |
import { initialState, State } from './state'; | |
export function featureReducer(state = initialState, action: Actions): State { | |
switch (action.type) { | |
case ActionTypes.LOGIN_REQUEST: | |
return { | |
...state, | |
error: null, | |
isLoading: true |
This file contains 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 { Action } from '@ngrx/store'; | |
import { User } from '../../models'; | |
export enum ActionTypes { | |
LOGIN_REQUEST = '[My Feature] Login Request', | |
LOGIN_FAILURE = '[My Feature] Login Failure', | |
LOGIN_SUCCESS = '[My Feature] Login Success' | |
} | |
export class LoginRequestAction implements Action { |
This file contains 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 { | |
createFeatureSelector, | |
createSelector, | |
MemoizedSelector | |
} from '@ngrx/store'; | |
import { MyModel } from '../models'; | |
import { featureAdapter, State } from './state'; |
This file contains 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 { | |
createFeatureSelector, | |
createSelector, | |
MemoizedSelector | |
} from '@ngrx/store'; | |
import { User } from '../../models'; | |
import { State } from './state'; |
This file contains 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 { Actions, Effect, ofType } from '@ngrx/effects'; | |
import { Action } from '@ngrx/store'; | |
import { Observable, of as observableOf } from 'rxjs'; | |
import { catchError, map, startWith, switchMap } from 'rxjs/operators'; | |
import { DataService } from '../../services/data.service'; | |
import * as featureActions from './actions'; | |
@Injectable() | |
export class MyFeatureStoreEffects { |
This file contains 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 { Actions, Effect, ofType } from '@ngrx/effects'; | |
import { Action } from '@ngrx/store'; | |
import { Observable, of as observableOf } from 'rxjs'; | |
import { catchError, map, startWith, switchMap } from 'rxjs/operators'; | |
import { DataService } from '../../services/data.service'; | |
import * as featureActions from './actions'; | |
@Injectable() | |
export class MyFeatureStoreEffects { |
OlderNewer