tkh44 / holen

Declarative fetch for React
MIT License
150 stars 16 forks source link

feat: add response transform and handle different response types #3

Closed vesparny closed 7 years ago

vesparny commented 7 years ago

This adds 2 features:

Usage:

<Holen
      url='https://jsonplaceholder.typicode.com/todos'
      type='json'
      transformResponse={data => {
        return data.map(e => Object.assign(e, {holen: true}))
      }}
        >
      {({data}) => <pre>{JSON.stringify(data, null, 2)}</pre>}
    </Holen>

I see unfetch provides a res.xml() method, but fetch does not (ping @developit) https://developer.mozilla.org/en-US/docs/Web/API/Response

That's the reason I only allowed json, text and blob as response types.

Still missing tests and docs

codecov-io commented 7 years ago

Codecov Report

Merging #3 into master will increase coverage by 0.2%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master       #3     +/-   ##
=========================================
+ Coverage   93.54%   93.75%   +0.2%     
=========================================
  Files           1        1             
  Lines          31       32      +1     
  Branches        4        4             
=========================================
+ Hits           29       30      +1     
  Misses          2        2
Impacted Files Coverage Δ
src/index.js 93.75% <100%> (+0.2%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 65b56a6...b8847e8. Read the comment docs.

tkh44 commented 7 years ago

I'm gonna go ahead and merge this, but we will want to add docs for these new features.

developit commented 7 years ago

Ooh - wow, time to rip out res.xml() for some bytes :D