Skip to content

Instantly share code, notes, and snippets.

View wesleygrimes's full-sized avatar

Wes Grimes wesleygrimes

View GitHub Profile
@wesleygrimes
wesleygrimes / entity-feature-store-module-actions.ts
Last active June 14, 2018 13:20
Entity Feature Store Module - Actions
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 {
@wesleygrimes
wesleygrimes / entity-feature-store-module-state.ts
Created May 30, 2018 18:14
Entity Feature Module - State
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())
});
@wesleygrimes
wesleygrimes / standard-feature-store-module-state.ts
Last active June 3, 2018 20:28
Standard Feature Module - State
import { User } from '../../models';
export interface State {
user: User | null;
isLoading: boolean;
error: string;
}
export const initialState: State = {
user: null,
@wesleygrimes
wesleygrimes / entity-feature-store-module-reducer.ts
Created May 30, 2018 18:20
Entity Feature Store Module - Reducer
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
@wesleygrimes
wesleygrimes / standard-feature-store-module-reducer.ts
Last active June 3, 2018 21:01
Standard Feature Store Module - Reducer
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
@wesleygrimes
wesleygrimes / standard-feature-store-module-actions.ts
Last active May 30, 2018 18:34
Standard Feature Store Module - Actions
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 {
@wesleygrimes
wesleygrimes / entity-feature-module-selectors.ts
Created May 30, 2018 18:39
Entity Feature Module - Selectors
import {
createFeatureSelector,
createSelector,
MemoizedSelector
} from '@ngrx/store';
import { MyModel } from '../models';
import { featureAdapter, State } from './state';
@wesleygrimes
wesleygrimes / standard-feature-store-module-selectors.ts
Last active July 18, 2018 19:27
Standard Feature Store Module - Selectors
import {
createFeatureSelector,
createSelector,
MemoizedSelector
} from '@ngrx/store';
import { User } from '../../models';
import { State } from './state';
@wesleygrimes
wesleygrimes / entity-feature-store-module-effects.ts
Last active May 31, 2018 15:21
Entity Feature Store Module - Effects.ts
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 {
@wesleygrimes
wesleygrimes / standard-feature-store-module-effects.ts
Last active June 3, 2018 20:33
Standard Feature Store Module - Effects
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 {