本文整理匯總了TypeScript中@ngrx/store.ActionReducer類的典型用法代碼示例。如果您正苦於以下問題:TypeScript ActionReducer類的具體用法?TypeScript ActionReducer怎麽用?TypeScript ActionReducer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ActionReducer類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: createReducer_SetsInitialState
@test createReducer_SetsInitialState()
{
type State = { num: number };
const initialState: State = Object.freeze({ num: 1 });
const reducer: ActionReducer<State> = createReducer({}, initialState);
const action = { type: "sometype", num: 0 };
assert.deepEqual(reducer(undefined, action), initialState);
}
示例2: createReducer_HandlesDirectActions
@test createReducer_HandlesDirectActions()
{
const handlers =
{
["add"]: (state: number, payload: { num: number }): number => state + payload.num
};
const reducer: ActionReducer<number> = createReducer(handlers);
const action = { type: "add", num: 1 };
assert.equal(reducer(1, action), 2);
}
示例3: addTransaction
export const transactions: ActionReducer<ITransactionStateRecord> = (state: ITransactionStateRecord, action: Action ): ITransactionStateRecord => {
switch (action.type){
case ADD_TRANSACTION:
return addTransaction(state, action);
case UPDATE_TRANSACTION:
return updateTransaction(state, action);
case DELETE_TRANSACTION:
return deleteTransaction(state, action);
}
return state;
}
示例4: AppReducer
export function AppReducer(state: any, action: any) {
if (String('<%= BUILD_TYPE %>') === 'dev') {
return developmentReducer(state, action);
} else {
return productionReducer(state, action);
}
}
示例5: reducer
export function reducer(state: IAppState, action: Action) {
if (environment.production) {
return productionReducer(state, action);
} else {
return developmentReducer(state, action);
}
}
示例6: reducer
export function reducer(state: any, action: any) {
if (String('<%= ENV %>') === 'prod') {
return productionReducer(state, action);
} else {
return developmentReducer(state, action);
}
}
示例7: reducer
export function reducer(state: State, action: any) {
const production = false;
if (production)
return prodReducer(state, action);
else
return devReducer(state, action);
}
示例8: it
it('should not turn off loading flags if you do not specify collections', () => {
const changeSet = createTestChangeSet();
let action: Action = new SaveEntities(changeSet, 'api/save', { correlationId: corid, isOptimistic: false });
// Pessimistic save turns on loading flags
let entityCache = entityCacheReducer({}, action);
expectLoadingFlags(entityCache, true);
action = new SaveEntitiesCancel(corid, 'Test Cancel'); // no names so no flags turned off.
entityCache = entityCacheReducer(entityCache, action);
expectLoadingFlags(entityCache, true);
});
示例9: reducer
export function reducer(state: any, action: any) {
const savedRecord: AppState = JSON.parse(sessionStorage.getItem('employerState'));
let record: AppState = savedRecord !== null ? savedRecord : state; //using this, will load record from localStorage into Store//need to load state from getSavedState
if (action.type === RESET_APP) {
record = undefined;
}
if (environment.production) {
return productionReducer(record, action);
}
else {
return developmentReducer(record, action);
}
}