Giter Site home page Giter Site logo

fetch-hoc's People

Contributors

danielr18 avatar eliihen avatar fc avatar joeydebreuk avatar maxsvargal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fetch-hoc's Issues

Refetch on same url

Is there any way to re fetch even if the url hasn't changed? An example of why this would be useful would be if the data stored at an endpoint changed from a user interaction, and the hoc needs to refresh its contents without completely wanting to reload the page. Considering forking off this repository to attempt to add a flag for this so the componentWillUpdate does not ignore it, but was wondering if you had any suggestions. Thanks!

How to pass authorization headers via props

Hi, I am wondering, since options is an object, how to add authorization headers, coming from props?

My use case:
I am writing an electron app, storing api keys to a redux store. Since the store is available through props, how can I pass props data to fetch-hoc's options?

Update to 0.2 breaks

After updating to 0.2, none of my requests are fired anymore, loading prop is always false and data always undefined.

RFC: Caching of results

Two components on the same page should not need to send two REST requests to fetch the same data. They should be able to share each others' data. This could be a nice performance boost in some cases.

This could also enable fetch-hoc to be a drop in replacement of redux, where you could have a fetchUser fetchHOC in many components around your app.

This can be solved with a cache module, which handles which URLs are currently being fetched.

To dodge some cache confusion, I feel it should clear the cache on unmount if no other components rely on this data so that next time a component mounts with this URL, it re-fetches it. This could be done by keeping track of how many components currently subscribe to the cache entry, and clearing it when it becomes 0.

An example of how this cache could look:

const cache = {
  'https://google.com': {
    subscribers: 2,
    data: (received data),
    fetching: true,
    awaitCompletion: Promise,
  },
};

And the corresponding FetchHOC code might look something like this:

const cacheEntry = cache[url];

if (cacheEntry && cacheEntry.fetching) {
  ++cacheEntry.subscribers;
  await cacheEntry.awaitCompletion();
  this.setState(/* data from cacheEntry */);
} else {
  cache[url] = {
    data: null,
    fetching: true, 
    subscribers: 1,
    awaitCompletion: new Promise(...),
  };
  // fetch as normal
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.