本文整理汇总了TypeScript中axios.verb函数的典型用法代码示例。如果您正苦于以下问题:TypeScript verb函数的具体用法?TypeScript verb怎么用?TypeScript verb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了verb函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: updateViaAjax
export function updateViaAjax(payl: AjaxUpdatePayload) {
const { uuid, statusBeforeError, dispatch, index } = payl;
const resource = findByUuid(index, uuid);
const { body, kind } = resource;
let verb: "post" | "put";
let url = urlFor(kind);
if (body.id) {
verb = "put";
if (!SINGULAR_RESOURCE.includes(unpackUUID(payl.uuid).kind)) {
url += body.id;
}
} else {
verb = "post";
}
maybeStartTracking(uuid);
return axios[verb]<typeof resource.body>(url, body)
.then(function (resp) {
const r1 = defensiveClone(resource);
const r2 = { body: defensiveClone(resp.data) };
const newTR = assign({}, r1, r2);
if (isTaggedResource(newTR)) {
dispatch(saveOK(newTR));
} else {
throw new Error("Just saved a malformed TR.");
}
})
.catch(function (err: UnsafeError) {
dispatch(updateNO({ err, uuid, statusBeforeError }));
return Promise.reject(err);
});
}
示例2: updateViaAjax
/** Shared functionality in create() and update(). */
function updateViaAjax(index: ResourceIndex,
uuid: string,
dispatch: Function) {
let resource = findByUuid(index, uuid);
let { body, kind } = resource;
let verb: "post" | "put";
let url = urlFor(kind);
if (body.id) {
verb = "put";
url += body.id;
} else {
verb = "post";
}
return axios[verb](url, body)
.then(function (resp: HttpData<typeof resource.body>) {
let r1 = defensiveClone(resource);
let r2 = { body: defensiveClone(resp.data) };
let newTR = _.assign({}, r1, r2);
if (isTaggedResource(newTR)) {
dispatch(updateOK(newTR));
} else {
throw new Error("Just saved a malformed TR.");
}
})
.catch(function (err: UnsafeError) {
dispatch(updateNO({ err, uuid }));
return Promise.reject(err);
});
}