fetch-wrap icon indicating copy to clipboard operation
fetch-wrap copied to clipboard

Can merge be replaced by ES6 destructuring?

Open pke opened this issue 3 years ago • 0 comments

I wonder if the usage of lodash/merge is obsolete for the operations most middlewares do here? They usually don't do deep merges so couldn't

return fetch(url, extendedFetch.merge({}, options, {
  headers: {
    "Authorization": "Bearer ...",
  }
}))

be replaced with:

return fetch(url, {
  ...options,
  headers: {
    ...options.headers,
    "Authorization": "Bearer ...",
  }
}))
it.only("should not matter", () => {
    const options = {
      body: "Test",
      headers: {
        "Accept": "text/plain",
      },
    }
    expect(extendFetch.merge({}, options, {
      headers: {
        "Content-Type": "text/plain",
      },
    })).toEqual({
      ...options,
      headers: {
        ...options.headers,
        "Content-Type": "text/plain",
      },
    })
  })

pke avatar Mar 06 '21 10:03 pke