本文整理匯總了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)
示例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));
}
示例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));
}
};
示例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));
}
示例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
}));
}
};
示例6: dispatch
) => dispatch => {
if (firebaseUser) {
dispatch(fetchMemberByUidIfNeeded(firebaseUser.uid));
}
dispatch(setFirebaseUser(firebaseUser));
};