本文整理汇总了TypeScript中@ngrx/store.combineReducers函数的典型用法代码示例。如果您正苦于以下问题:TypeScript combineReducers函数的具体用法?TypeScript combineReducers怎么用?TypeScript combineReducers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了combineReducers函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: combineReducers
import * as fromRouter from '@ngrx/router-store';
import { compose } from '@ngrx/core/compose';
import { combineReducers } from '@ngrx/store';
import { createSelector } from 'reselect';
import * as fromScouts from './scouts';
export interface State {
scouts: fromScouts.State;
router: fromRouter.RouterState;
}
const reducers = {
scouts: fromScouts.reducer,
router: fromRouter.routerReducer
}
const reducer: ActionReducer<State> = combineReducers(reducers);
export function rootReducer(state: any, action: any) {
return reducer(state, action);
}
export const getScoutsState = (state: State) => state.scouts;
export const getScoutIds = createSelector(getScoutsState, fromScouts.getIds);
export const getScoutEntities = createSelector(getScoutsState, fromScouts.getEntities);
export const getSelectedScoutId = createSelector(getScoutsState, fromScouts.getSelectedId);
export const getSelectedScout = createSelector(getScoutsState, fromScouts.getSelected);
export const getScout = (id: string) => createSelector(getScoutsState, fromScouts.getById(id));
export const getAllScouts = createSelector(getScoutsState, fromScouts.getAll);
示例2: bootstrap
//main entry point
import {bootstrap} from 'angular2/platform/browser';
import {provide} from 'angular2/core'
import {App} from './app';
import {createStore, combineReducers, Store} from '@ngrx/store'
import * as devtools from '@ngrx/devtools'
import {todos, visibilityFilter} from './todos';
import 'rxjs/Rx'
let enhanced = devtools.instrument()(createStore);
bootstrap(App, [
provide(Store, {useValue: enhanced(combineReducers({todos, visibilityFilter})) })
])
.catch(err => console.error(err));
示例3: combineReducers
import {articles} from './article';
import {combineReducers} from '@ngrx/store';
export * from './article';
export default combineReducers({ articles });
示例4: beforeEach
beforeEach(() => {
combination = combineReducers(reducers, initialState);
});
示例5: switch
return state.map((p: CcyPair) => {
if (p.value === action.payload.ccypair) {
p.favourite = action.payload.favourite;
}
return p;
});
default:
return state;
}
};
export const values: Reducer<CcyPairValues> =
(state: CcyPairValues = {}, action: Action): CcyPairValues => {
switch (action.type) {
case UNDERLYING_CCYPAIR_VALUE_UPDATE:
return Object.assign({}, state, {
[action.payload.ccypair]: action.payload
});
default:
return state;
}
};
export const underlyings: Reducer<Underlyings> = combineReducers({
ccypairs, values
});
示例6: compose
ďťżimport { ActionReducer } from '@ngrx/store';
import { combineReducers } from '@ngrx/store';
import { storeFreeze } from 'ngrx-store-freeze';
import { compose } from "@ngrx/core";
import { environment } from './environments/environment';
import * as person from './person/person.store';
import * as location from './location/location.store';
import * as trip from './trip/trip.store';
export interface AppState {
person: person.PersonState,
location: location.LocationState,
trip: trip.TripState
}
const reducers = {
person: person.PersonReducer,
location: location.LocationReducer,
trip: trip.TripReducer
}
const developmentReducer: ActionReducer<AppState> = compose(storeFreeze, combineReducers)(reducers);
const productionReducer: ActionReducer<AppState> = combineReducers(reducers);
export function AppReducer(state: any, action: any) {
if (environment.enableStoreFreeze && !environment.production)
return developmentReducer(state, action);
else
return productionReducer(state, action);
}
示例7: compose
* Because metareducers 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 storeLogger. Remember that compose applies
* the result from right to left.
*/
const reducers = {
search: fromSearch.reducer,
books: fromBooks.reducer,
collection: fromCollection.reducer,
layout: fromLayout.reducer,
router: fromRouter.routerReducer,
};
const developmentReducer = compose(storeFreeze, combineReducers)(reducers);
const productionReducer = combineReducers(reducers);
export function reducer(state: any, action: any) {
if (PROD) {
return productionReducer(state, action);
}
else {
return developmentReducer(state, action);
}
}
/**
* A selector function is a map function factory. We pass it parameters and it
* returns a function that maps from the larger state tree into a smaller
* piece of state. This selector simply selects the `books` state.
示例8: combineReducers
}
export const reducer = combineReducers({
artifactEquation: fromArtifactEquation.reducer,
artifactEstimator: fromArtifactEstimator.reducer,
locusArtifactEstimator: fromLocusArtifactEstimator.reducer,
artifactEstimatorLocusParams: fromArtifactEstimatorLocusParams.reducer,
artifactEstimatorProject: fromArtifactEstimatorProject.reducer,
bin: fromBin.reducer,
locusBinSet: fromLocusBinSet.reducer,
binEstimatorLocusParams: fromBinEstimatorLocusParams.reducer,
binEstimatorProject: fromBinEstimatorProject.reducer,
genotypingLocusParams: fromGenotypingLocusParams.reducer,
genotypingProject: fromGenotypingProject.reducer,
locusSet: fromLocusSet.reducer,
locus: fromLocus.reducer,
projectChannelAnnotations: fromProjectChannelAnnotations.reducer,
projectSampleAnnotations: fromProjectSampleAnnotations.reducer,
quantificationBiasEstimatorLocusParams: fromQuantificationBiasEstimatorLocusParams.reducer,
quantificationBiasEstimatorProject: fromQuantificationBiasEstimatorProject.reducer,
controlSampleAssociation: fromControlSampleAssociation.reducer,
control: fromControl.reducer,
genotype: fromGenotype.reducer,
sampleLocusAnnotation: fromSampleLocusAnnotation.reducer,
sample: fromSample.reducer,
channel: fromChannel.reducer,
ladder: fromLadder.reducer,
plate: fromPlate.reducer,
well: fromWell.reducer
});
export const models = {
示例9: combineReducers
import { combineReducers } from '@ngrx/store';
import { counterReducer } from './counter-reducer';
import { curseReducer } from './curse-reducer';
export default combineReducers({
counter: counterReducer,
curse: curseReducer
});
示例10: switch
export type StudentAction =
FetchStudentFulFilledAction
& FetchStudentAction
& FetchStudentErrorAction
& CreateStudentAction
& CreateStudentFulFilledAction
& CreateStudentErrorAction
& UpdateStudentCountFulFiiledAction;
export type students = ActionReducer<Student[], StudentAction>;
export const students: students = (state = [], action) => {
switch (action.type) {
case FETCH_STUDENT_FULFILLED:
return action.students;
case CREATE_STUDENT_FULFILLED:
return [...state, action.students];
case UPDATE_STUDENT_COUNT_FULFILLED:
const item = state.find(s => s.id === action.id);
item.count++;
state[state.findIndex(s => s.id === action.id)] = item;
return state;
default:
return state;
}
};
export const student = combineReducers<StudentState, StudentAction> ({
students
});