Angular Ngrx / store, возврат магазина не определен - PullRequest
0 голосов
/ 14 сентября 2018

Я не знаю, если это проблема установки или как я звоню в магазин. Наша команда настроила это так, что я не проектировал это.

вот урезанная версия app.module.ts

import { reducer2 } from './reducers';

@NgModule({
...
  imports: [
    BrowserModule,
    InboxRouteRoutes,
    HttpModule,
    HttpClientModule,
    InMemoryWebApiModule.forRoot(InMemoryDataService, { delay: 600 }),
    StoreModule.forRoot(reducer2)],
  providers: [
    DatabaseService,
    HttpService,
    HttpErrorHandler,
    MessagingService,
    InitialzationServiceService
  ],
  bootstrap: [AppComponent]
})
export class AppModule { 


}

как магазин называется в модуле

  constructor(public store: Store<State2>) { 


this.store.select(getAllCampaigns).map(item => this.campaigns$ = item)

Как настроен комбинированный редуктор

export interface State2 {
  business: fromBusiness.State;
  campaign: fromCampaign.State;
  conversation: fromConversation.State;
  message: fromMessage.State;
  subscription: fromSubscription.State;
  userprofile: fromUserProfile.State;
}


/**
 * Because metal reducers take a reducer function and return a new reducer,
 * we can use our compose helper to chain them together. Here we are
 * using combineReducers to make our top-level reducer, and then
 * wrapping that in store longer. Remember that compose applies
 * the result from right to left.
 */
const reducers = {
  campaign: fromCampaign.campaignReducer,
  business: fromBusiness.businessReducer,
  conversation: fromConversation.conversationReducer,
  message: fromMessage.messageReducer,
  subscription: fromSubscription.subscriptionReducer,
  userprofile: fromUserProfile.userprofileReducer,
};

/*const developmentReducer: ActionReducer<State> = compose(storeFreeze, combineReducers)(reducers);*/
const productionReducer: ActionReducer<State2> = combineReducers(reducers);

export function reducer2(state: any, action: any) {
  //if (environment.production) {
    return productionReducer(state, action);
  /*} else {
    return developmentReducer(state, action);
  }*/
}
export const getCampaignState = (state: State2) => state.campaign;

export const getAllCampaigns = createSelector(getCampaignState, fromCampaign.getAll);

Так настроен редуктор кампании.

export interface State {
    ids: string[];
    entities: { [id: string]: Campaign };
    selectedCampaignId: string | null;
    loading: boolean;
    loaded: boolean;
    query: string;
  };

  export const initialState: State = {
    ids: [],
    entities: {},
    selectedCampaignId: null,
    loading: false,
    loaded: false,
    query: ''
  };


//added to have a payload available
export interface CustomAction extends Action {
    type: string,
    payload?: any;
}

//"Actions" has access to the payload


//made Campaign an array
export const campaignReducer= (state = initialState, action: Actions) => {

    switch (action.type) {

        case ActionTypes.CREATE_CAMPAIGN:
           // return [...state, action.payload];
           return state;
            //should add the campaign to an empty array

        case  ActionTypes.LOAD_CAMPAIGN:
            return state;

        case ActionTypes.DELETE_CAMPAIGN:
            return state;
            //not sure we will delete the campaign here.
            // we might delete it from the conversation it belongs too.

        case ActionTypes.UPDATE_CAMPAIGN:
        return state;
        /*
            return state.map(campaign => {
                campaign.externalbusinessid === action.payload.externalbusinessid 
                ? Object.assign({}, campaign, action.payload): campaign
            })*/
            //compares all campaigns finding the one that matches the payload and
            //returns that campaign again.

        case ActionTypes.UPDATE_CAMPAIGN_CLICKEDTHROUGH:
        /*
            return state.map(campaign => {
                campaign.externalbusinessid === action.payload.externalbusinessid
                ? Object.assign({}, campaign, {clickedthrough: true}): campaign
            })*/
            return state;
            //should compaire the externalbusinessId and for the one that passes
            //changes the clickedthrough value to true


        case ActionTypes.UPDATE_CAMPAIGN_VIEWED:
            return state;

        case ActionTypes.UPDATE_CAMPAIGN_VIEW_TIME:
            return state;


        case ActionTypes.CREATE_CAMPAIGN_SUCCESS:
            return state;

        case  ActionTypes.LOAD_CAMPAIGN_SUCCESS:
            return state;

        case ActionTypes.DELETE_CAMPAIGN_SUCCESS:
            return state;

        case ActionTypes.UPDATE_CAMPAIGN_SUCCESS:
            return state;

        case ActionTypes.UPDATE_CAMPAIGN_CLICKEDTHROUGH_SUCCESS:
            return state;

        case ActionTypes.UPDATE_CAMPAIGN_VIEWED_SUCCESS:
            return state;

        case ActionTypes.UPDATE_CAMPAIGN_VIEW_TIME_SUCCESS:
            return state;

        default:
            return state;
    }
}



/**
 * Because the data structure is defined within the reducer it is optimal to
 * locate our selector functions at this level. If the store is to be thought of
 * as a database, and reducers the tables, selectors can be considered the
 * queries into the said database. Remember to keep your selectors small and
 * focused so they can be combined and composed to fit each particular
 * use-case.
 */

export const getEntities = (state: State) => state.entities;

export const getIds = (state: State) => state.ids;

export const getSelectedId = (state: State) => state.selectedCampaignId;

export const getSelected = createSelector(getEntities, getSelectedId, (entities, selectedId) => {
  return entities[selectedId];
});

export const getAll = createSelector(getEntities, getIds, (entities, ids) => {
  return ids.map(id => entities[id]);
});

export const getQuery = (state: State) => state.query;

export const getLoading = (state: State) => state.loading;

export const getLoaded = (state: State) => state.loaded;

Я пытаюсь получить значения из магазина кампании и запустить отправку обратно в магазин. Каждый раз, когда я пытаюсь получить значения из хранилища, он возвращает неопределенный или странный объект в виде редуктора. Может кто-нибудь, пожалуйста, помогите мне понять, как я это неправильно называю

...