本文整理匯總了TypeScript中redux.Reducer類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Reducer類的具體用法?TypeScript Reducer怎麽用?TypeScript Reducer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Reducer類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: return
return (state: S, action: any) => {
if (action.type === STATE_LOADING_DONE) {
return appReducer(action.payload, action)
}
return appReducer(state, action)
}
示例2: deepFreeze
export const reducerTester = <State>(): Given<State> => {
let reducerUnderTest: Reducer<State, ActionOf<any>> = null;
let resultingState: State = null;
let initialState: State = null;
const givenReducer = (reducer: Reducer<State, ActionOf<any>>, state: State): When<State> => {
reducerUnderTest = reducer;
initialState = { ...state };
initialState = deepFreeze(initialState);
return instance;
};
const whenActionIsDispatched = (action: ActionOf<any>): Then<State> => {
resultingState = reducerUnderTest(initialState, action);
return instance;
};
const thenStateShouldEqual = (state: State): Then<State> => {
expect(state).toEqual(resultingState);
return instance;
};
const instance: ReducerTester<State> = { thenStateShouldEqual, givenReducer, whenActionIsDispatched };
return instance;
};
示例3: it
it ('should handle ADDING and ADDED', () => {
let reduc = reducer(undefined, {
type: `${C.ADDING}`,
meta: {className}
})
verifyClassRecord(reduc.get(className), 'adding');
reduc = reducer(reduc, {
type: `${C.ADDED}`,
meta: {className}
})
verifyClassRecord(reduc.get(className));
});
示例4: it
it ('should handle FINDING_LIST', () => {
let reduc = reducer(undefined, {
type: `${C.FINDING_LIST}`,
meta: {uri}
})
expect( reduc.get(uri).get('loading') ).toBeTruthy()
reduc = reducer(reduc, {
type: `${C.FOUND_LIST}`,
meta: {uri}
})
expect( reduc.get(uri).loading ).toBeFalsy()
});
示例5: it
it ('should handle FIND_CASE', () => {
expect(
reducer(undefined, {
type: `${FIND}_${type}`,
payload: {
result: ['/cases/1'],
items: {
'/cases/1': {
_links: {self: {href: '/cases/1'}}, _embedded: {entries: [{}]}
}
}
}
})
).toEqual(
{
result: ['/cases/1'],
loadingMany: false,
loadingOne: false,
deleting: false,
patching: false,
adding: false,
items: {
'/cases/1': {
_links: {self: {href: '/cases/1'}}, _embedded: {entries: [{}]}
}
},
meta: {}
}
);
});
示例6: it
it ('should handle DESTROYING_CASE', () => {
let reduc = reducer(undefined, {
type: `${DESTROYING}_${type}`
})
verifyDefault(reduc, 'deleting');
expect( reduc.deleting ).toBeTruthy();
});