本文整理汇总了TypeScript中typescript-fsa.isType函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isType函数的具体用法?TypeScript isType怎么用?TypeScript isType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isType函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
const reducer: Reducer<State> = (state = defaultState, action) => {
if (isType(action, getLinodeTypesActions.started)) {
return {
...state,
loading: true
};
}
if (isType(action, getLinodeTypesActions.done)) {
const { result } = action.payload;
return {
...state,
loading: false,
lastUpdated: Date.now(),
entities: result,
results: result.map(t => t.id)
};
}
if (isType(action, getLinodeTypesActions.failed)) {
const { error } = action.payload;
return {
...state,
loading: false,
error
};
}
return state;
};
示例2: updateOrAdd
const reducer: Reducer<State> = (state = defaultState, action) => {
if (isType(action, getImagesRequest)) {
return {
...state,
loading: true,
};
}
if (isType(action, getImagesSuccess)) {
const { payload } = action;
return {
...state,
loading: false,
lastUpdated: Date.now(),
entities: payload,
results: payload.map(t => t.id)
};
}
if (isType(action, getImagesFailure)) {
const { payload } = action;
return {
...state,
loading: false,
error: payload,
};
}
if (isType(action, removeImage)) {
const { payload } = action;
/**
* Events provide a numeric ID, but the actual ID is a string. So we have to respond
* to both potentials.
* ![Hard to work](https://media.giphy.com/media/juSraIEmIN5eg/giphy.gif)
*/
const id = typeof payload === 'string' ? payload : `private/${payload}`
const updated = state.entities.filter((image) => image.id !== id);
return {
...state,
entities: updated,
results: updated.map((i) => i.id),
};
}
if (isType(action, addOrUpdateImage)) {
const { payload } = action;
const updated = updateOrAdd(payload, state.entities);
return {
...state,
entities: updated,
results: updated.map((i) => i.id),
}
}
return state;
};
示例3:
const reducer: Reducer<State> = (
state: State = defaultState,
action: Action<Linode.Profile>
) => {
if (isType(action, getProfileActions.started)) {
const {} = action.payload;
return { ...state, loading: true };
}
if (isType(action, getProfileActions.done)) {
const { result } = action.payload;
return { ...state, loading: false, lastUpdated: Date.now(), data: result };
}
if (isType(action, getProfileActions.failed)) {
const { error } = action.payload;
return { ...state, loading: false, lastUpdated: Date.now(), error };
}
if (isType(action, handleUpdate)) {
return {
...state,
loading: false,
lastUpdated: Date.now(),
data: action.payload
};
}
return state;
};
示例4:
const reducer: Reducer<State> = (state = defaultState, action) => {
if (isType(action, regionsRequestActions.started)) {
return {
...state,
loading: true,
}
}
if (isType(action, regionsRequestActions.done)) {
const { result } = action.payload;
return {
...state,
loading: false,
lastUpdated: Date.now(),
entities: result,
results: result.map((r) => r.id),
}
}
if (isType(action, regionsRequestActions.failed)) {
const { error } = action.payload;
return {
...state,
loading: false,
error,
}
}
return state;
};
示例5: updateEvents
const reducer: Reducer<State> = (state = defaultState, action: AnyAction) => {
if (isType(action, addEvents)) {
const { payload: events } = action;
const {
events: prevEvents,
inProgressEvents: prevInProgressEvents,
mostRecentEventTime,
} = state;
const updatedEvents = updateEvents(prevEvents, events);
return {
...state,
events: updatedEvents,
mostRecentEventTime: events.reduce(mostRecentCreated, mostRecentEventTime),
countUnseenEvents: getNumUnseenEvents(updatedEvents),
inProgressEvents: updateInProgressEvents(prevInProgressEvents, events),
};
}
if (isType(action, updateEventsAsSeen)) {
return {
...state,
events: state.events.map((event) => ({ ...event, seen: true })),
countUnseenEvents: 0,
}
}
return state;
};
示例6: fbScenarioReducer
export function fbScenarioReducer(state: FBScenarioState = initialState, action: Action): FBScenarioState {
const newState: FBScenarioState = _.cloneDeep(state);
if (isType(action, FBScenarioActions.changeName)) {
newState.formData.name = action.payload;
return newState;
}
if (isType(action, FBScenarioActions.changeEntryPoint)) {
newState.formData.entryPoint = action.payload;
return newState;
}
if (isType(action, FBScenarioActions.requestPosts)) {
return newState;
}
if (isType(action, FBScenarioActions.receivePosts)) {
return newState;
}
if (isType(action, FBScenarioActions.failePosts)) {
return newState;
}
if (isType(action, FBScenarioActions.cancel)) {
return initialState;
}
if (isType(action, FBScenarioActions.openModal)) {
newState.modal.isShow = true;
newState.modal.type = action.payload;
return newState;
}
if (isType(action, FBScenarioActions.closeModal)) {
newState.modal.isShow = false;
newState.modal.type = ModalType.NONE;
return newState;
}
return newState;
}
示例7: testIsType
function testIsType() {
const withPayload = actionCreator<{foo: string}>('WITH_PAYLOAD');
const withoutPayload = actionCreator('WITHOUT_PAYLOAD');
if (isType(action, withPayload)) {
const foo: string = action.payload.foo;
// typings:expect-error
action.payload.bar;
}
if (isType(action, withoutPayload)) {
// typings:expect-error
const foo: {} = action.payload;
}
}
示例8:
const reducer: Reducer<State> = (state: State = defaultState, action) => {
if (isType(action, profileRequest)) {
return { ...state, loading: true };
}
if (isType(action, profileRequestSuccess)) {
const { payload } = action;
return { ...state, loading: false, data: payload, lastUpdated: Date.now() };
}
if (isType(action, profileRequestFail)) {
const { payload } = action;
return { ...state, loading: false, error: payload };
}
return state;
};
示例9: onStart
const reducer: Reducer<State> = (state = defaultState, action) => {
/** Get all */
if (isType(action, getAllNodeBalancersActions.started)) {
return onStart(state);
}
if (isType(action, getAllNodeBalancersActions.done)) {
const { result } = action.payload;
if (result.length === 0) {
return {
...state,
loading: false,
lastUpdated: Date.now()
};
}
return onGetAllSuccess(result, state);
}
if (isType(action, getAllNodeBalancersActions.failed)) {
const { error } = action.payload;
return onError(error, state);
}
/** Create */
if (isType(action, createNodeBalancersActions.done)) {
const { result } = action.payload;
return onCreateOrUpdate(result, state);
}
/** Update */
if (isType(action, updateNodeBalancersActions.done)) {
const { result } = action.payload;
return onCreateOrUpdate(result, state);
}
/** Delete */
if (isType(action, deleteNodeBalancerActions.done)) {
const {
params: { nodeBalancerId }
} = action.payload;
return onDeleteSuccess(nodeBalancerId, state);
}
/** Add */
if (isType(action, getNodeBalancerWithConfigsActions.done)) {
const { result } = action.payload;
return onCreateOrUpdate(result, state);
}
return state;
};
示例10:
export const reducer: Reducer<State> = (state = defaultState, action) => {
// OPEN
if (isType(action, openBucketDrawer)) {
return {
...state,
isOpen: true
};
}
// CLOSE
if (isType(action, closeBucketDrawer)) {
return {
...state,
isOpen: false
};
}
return state;
};