本文整理汇总了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));
};