本文整理汇总了TypeScript中redux-thunk.Dispatch类的典型用法代码示例。如果您正苦于以下问题:TypeScript Dispatch类的具体用法?TypeScript Dispatch怎么用?TypeScript Dispatch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Dispatch类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
export const getUsers = () => async (
dispatch: Dispatch<Action>,
getState: GetState
) => {
try {
const {
members: {list},
} = getState()
const apiUsers = await client.users.getAll()
const allUsers = apiUsers.reduce((acc, u) => _.set(acc, u.id, u), {})
const users = _.omit(allUsers, list.map(m => m.id))
dispatch(setUsers(RemoteDataState.Done, users))
} catch (e) {
console.error(e)
dispatch(setMembers(RemoteDataState.Error))
}
}
示例2: async
export const getBuckets = () => async (
dispatch: Dispatch<Action>,
getState: () => AppState
) => {
try {
dispatch(setBuckets(RemoteDataState.Loading))
const {
orgs: {org},
} = getState()
const buckets = await client.buckets.getAll(org.id)
dispatch(setBuckets(RemoteDataState.Done, buckets))
} catch (e) {
console.error(e)
dispatch(setBuckets(RemoteDataState.Error))
dispatch(notify(getBucketsFailed()))
}
}
示例3: async
) => async (dispatch: Dispatch<Action>, getState: GetState) => {
try {
const {
orgs: {org},
} = getState()
const createdVariable = await createVariableFromTemplateAJAX(
template,
org.id
)
dispatch(
setVariable(createdVariable.id, RemoteDataState.Done, createdVariable)
)
dispatch(notify(createVariableSuccess(createdVariable.name)))
} catch (e) {
console.error(e)
dispatch(notify(createVariableFailed(e.response.data.message)))
}
}
示例4: async
export const getAuthorizations = () => async (
dispatch: Dispatch<Action>,
getState: () => AppState
) => {
try {
dispatch(setAuthorizations(RemoteDataState.Loading))
const {
orgs: {org},
} = getState()
const authorizations = await client.authorizations.getAll(org.id)
dispatch(setAuthorizations(RemoteDataState.Done, authorizations))
} catch (e) {
console.error(e)
dispatch(setAuthorizations(RemoteDataState.Error))
dispatch(notify(authorizationsGetFailed()))
}
}
示例5: async
export const deleteMember = (member: Member) => async (
dispatch: Dispatch<Action>,
getState: GetState
) => {
try {
const {
orgs: {
org: {id},
},
} = getState()
await client.organizations.removeMember(id, member.id)
dispatch(removeMember(member.id))
dispatch(notify(memberRemoveSuccess(member.name)))
} catch (e) {
console.error(e)
dispatch(notify(memberRemoveFailed(member.name)))
}
}
示例6: async
export const createBucket = (bucket: Bucket) => async (
dispatch: Dispatch<Action>,
getState: () => AppState
) => {
try {
const {
orgs: {org},
} = getState()
const createdBucket = await client.buckets.create({
...bucket,
organizationID: org.id,
})
dispatch(addBucket(createdBucket))
} catch (e) {
console.error(e)
dispatch(notify(bucketCreateFailed()))
throw e
}
}
示例7: async
export const selectTagValue = (index: number, value: string) => async (
dispatch: Dispatch<Action>,
getState: GetState
) => {
const tags = getActiveQuery(getState()).builderConfig.tags
const values = tags[index].values
let newValues: string[]
if (values.includes(value)) {
newValues = values.filter(v => v !== value)
} else {
newValues = [...values, value]
}
dispatch(setBuilderTagValuesSelection(index, newValues))
if (index === tags.length - 1 && newValues.length) {
dispatch(addTagSelector())
} else {
dispatch(loadTagSelector(index + 1))
}
}
示例8: async
export const createNoteCell = (dashboardID: string) => async (
dispatch: Dispatch<Action>,
getState: GetState
) => {
const dashboard = getState().dashboards.list.find(d => d.id === dashboardID)
if (!dashboard) {
throw new Error(`could not find dashboard with id "${dashboardID}"`)
}
const {note} = getState().noteEditor
const view = createView<MarkdownView>(ViewType.Markdown)
view.properties.note = note
return dispatch(createCellWithView(dashboard, view))
}