當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript typescript-fsa.isType函數代碼示例

本文整理匯總了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;
};
開發者ID:linode,項目名稱:manager,代碼行數:32,代碼來源:linodeType.reducer.ts

示例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;
};
開發者ID:displague,項目名稱:manager,代碼行數:60,代碼來源:image.reducer.ts

示例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;
};
開發者ID:displague,項目名稱:manager,代碼行數:30,代碼來源:profile.reducer.ts

示例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;
};
開發者ID:displague,項目名稱:manager,代碼行數:33,代碼來源:regions.reducer.ts

示例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;
};
開發者ID:displague,項目名稱:manager,代碼行數:30,代碼來源:event.reducer.ts

示例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;
}
開發者ID:kanecop,項目名稱:react_laravel,代碼行數:34,代碼來源:FBScenario.ts

示例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;
  }
}
開發者ID:m0a,項目名稱:typescript-fsa,代碼行數:16,代碼來源:index.ts

示例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;
};
開發者ID:linode,項目名稱:manager,代碼行數:19,代碼來源:account.reducer.ts

示例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;
};
開發者ID:linode,項目名稱:manager,代碼行數:58,代碼來源:nodeBalancer.reducer.ts

示例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;
};
開發者ID:linode,項目名稱:manager,代碼行數:19,代碼來源:bucketDrawer.reducer.ts


注:本文中的typescript-fsa.isType函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。