Skip to content

Instantly share code, notes, and snippets.

View wesleygrimes's full-sized avatar

Wes Grimes wesleygrimes

View GitHub Profile
@wesleygrimes
wesleygrimes / root-store-module.ts
Last active May 31, 2018 15:21
Root Store Module
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { EffectsModule } from '@ngrx/effects';
import { StoreModule } from '@ngrx/store';
import { MyFeatureStoreModule } from './my-feature-store/';
import { MyOtherFeatureStoreModule } from './my-other-feature-store/';
@NgModule({
imports: [
CommonModule,
@wesleygrimes
wesleygrimes / root-state.ts
Last active February 15, 2022 05:03
Root State
import { MyFeatureStoreState } from './my-feature-store';
import { MyOtherFeatureStoreState } from './my-other-feature-store';
export interface State {
myFeature: MyFeatureStoreState.State;
myOtherFeature: MyOtherFeatureStoreState.State;
}
@wesleygrimes
wesleygrimes / feature-store-module-index.ts
Created May 30, 2018 19:00
Feature Store Module - Barrel Exports
import * as MyFeatureStoreActions from './actions';
import * as MyFeatureStoreSelectors from './selectors';
import * as MyFeatureStoreState from './state';
export {
MyFeatureStoreModule
} from './my-feature-store.module';
export {
MyFeatureStoreActions,
@wesleygrimes
wesleygrimes / feature-store-module.ts
Last active May 31, 2018 15:22
Feature Store Module - Module
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { EffectsModule } from '@ngrx/effects';
import { StoreModule } from '@ngrx/store';
import { MyFeatureStoreEffects } from './effects';
import { featureReducer } from './reducer';
@NgModule({
imports: [
CommonModule,
@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 {
@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-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-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-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 / 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