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