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


TypeScript redux.ActionCreator類代碼示例

本文整理匯總了TypeScript中redux.ActionCreator的典型用法代碼示例。如果您正苦於以下問題:TypeScript ActionCreator類的具體用法?TypeScript ActionCreator怎麽用?TypeScript ActionCreator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ActionCreator類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: addTodo

import {
  ActionCreator,
  Action,
  Dispatch,
  bindActionCreators,
  ActionCreatorsMapObject
} from 'redux'

interface AddTodoAction extends Action {
  text: string
}

const addTodo: ActionCreator<AddTodoAction> = (text: string) => ({
  type: 'ADD_TODO',
  text
})

const addTodoAction: AddTodoAction = addTodo('test')

type AddTodoThunk = (dispatch: Dispatch) => AddTodoAction

const addTodoViaThunk: ActionCreator<AddTodoThunk> = (text: string) => (
  dispatch: Dispatch
) => ({
  type: 'ADD_TODO',
  text
})

declare const dispatch: Dispatch

const boundAddTodo = bindActionCreators(addTodo, dispatch)
開發者ID:Evan726,項目名稱:redux,代碼行數:31,代碼來源:actionCreators.ts

示例2: fetchMemberByUid

async function fetchMemberByUid(dispatch: Dispatch<AppState>, uid: string) {
  dispatch(requestMemberByUid(uid));
  const memberDoc = await db
    .collection("members")
    .doc(uid)
    .get();
  // TODO error handling
  dispatch(receiveMember(memberDoc, uid, false));
}
開發者ID:rahafoundation,項目名稱:raha-web-app,代碼行數:9,代碼來源:index.ts

示例3: async

 return async (dispatch: Dispatch<IAction<IFeature[]>>) => {
     try {
         const features: IFeature[] = await api.getFeatures(feature.scope)
         if (feature.scope === FeatureScope.Web) {
             dispatch(getWebFeaturesSuccess(features, feature));
         } else {
             dispatch(getSiteFeaturesSuccess(features, feature));
         }
     } catch (error) {
         dispatch(handleAsyncError(constants.ERROR_MESSAGE_GETTING_FEATURES, error));
     }
 };
開發者ID:DariuS231,項目名稱:ChromeSPPropertiesAdmin,代碼行數:12,代碼來源:spFeaturesActions.ts

示例4: fetchMemberByMid

async function fetchMemberByMid(
  dispatch: Dispatch<AppState>,
  username: string
) {
  dispatch(requestMemberByUsername(username));
  const memberQuery = await db
    .collection("members")
    .where("username", "==", username)
    .get();
  if (memberQuery.docs.length > 1) {
    alert(
      `Found multiple matching member ${username}, please email bugs@raha.io`
    );
  }
  const memberDoc = memberQuery.docs.length === 1 ? memberQuery.docs[0] : null;
  dispatch(receiveMember(memberDoc, username, true));
}
開發者ID:rahafoundation,項目名稱:raha-web-app,代碼行數:17,代碼來源:index.ts

示例5: async

 return async (dispatch: Dispatch<IAction<ISiteContent[]>>) => {
     try {
         const siteContent: ISiteContent[] = await api.getLists();
         if (typeof messageData !== "undefined") {
             dispatch(setAllSiteContentAndMessage(siteContent, messageData));
         } else {
             dispatch(setAllSiteContent(siteContent));
         }
     } catch (error) {
         // tslint:disable-next-line:no-console
         console.log(error);
         dispatch(setMessageData({
             message: constants.ERROR_MESSAGE_GET_ALL_SITE_CONTENT,
             showMessage: true,
             type: MessageBarType.error
         }));
     }
 };
開發者ID:DariuS231,項目名稱:ChromeSPPropertiesAdmin,代碼行數:18,代碼來源:spSiteContentActions.ts

示例6: dispatch

) => dispatch => {
  if (firebaseUser) {
    dispatch(fetchMemberByUidIfNeeded(firebaseUser.uid));
  }
  dispatch(setFirebaseUser(firebaseUser));
};
開發者ID:rahafoundation,項目名稱:raha-web-app,代碼行數:6,代碼來源:index.ts


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