當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript axios.verb函數代碼示例

本文整理匯總了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);
    });
}
開發者ID:FarmBot,項目名稱:Farmbot-Web-API,代碼行數:31,代碼來源:crud.ts

示例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);
    });
}
開發者ID:MrChristofferson,項目名稱:Farmbot-Web-API,代碼行數:30,代碼來源:crud.ts


注:本文中的axios.verb函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。