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-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-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-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 / 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 {