Skip to content

Instantly share code, notes, and snippets.

@amcdnl
Last active March 8, 2018 16:34
Show Gist options
  • Save amcdnl/6998c0dbad7af5f424dc7719527f9fb8 to your computer and use it in GitHub Desktop.
Save amcdnl/6998c0dbad7af5f424dc7719527f9fb8 to your computer and use it in GitHub Desktop.
root = {
  cart: { //=> cartReducer
    checkout: [], //=> checkoutReducer
    saved: [],
    left: false
  }
}

function cartReducer = (state, action) => {
  switch(action.type) {
    'LEFT': return { ...state, left: action.payload };
  }
}

function checkoutReducer = (state, action) => {
  switch(action.type) {
    'ADD_ITEM': return [...state, action.payload[;
  }
}
@Dercetech
Copy link

./app/app.module.ts

import {reducers} from './shared/store/reducers';

...
@NgModule({
  imports: [  StoreModule.forRoot(reducers, {  }), ...

...

./app/shared/store/reducers/index.ts

import * as fromCart from './cart.reducers';

export interface State {
  cart: fromCart.CartState
}

export const reducers: ActionReducerMap<State> = {
  cart: fromCart.reducers,
};

./app/shared/store/reducers/cart.reducers.ts

import * as fromCheckout from './checkout.reducers';

export interface CartState {
  checkout: fromCheckout.CheckoutState,
  saved: any[]
}

export const reducers: ActionReducerMap<State> = {
  checkout: fromCheckout.checkoutReducer,
};

./app/shared/store/reducers/checkout.reducers.ts

export interface CheckoutState {
  step: any
}

export function checkoutReducer = (state, action) => {
  switch(action.type) {
    'LEFT': return { ...state, left: action.payload };
  }
}

export const reducers: ActionReducerMap<State> = {
  checkout: fromCheckout.checkoutReducer,
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment