本文整理匯總了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))
}