Giter VIP home page Giter VIP logo

Comments (9)

hnordt avatar hnordt commented on May 22, 2024

I like both ideas. 👍

Just one suggestion, instead data:

connect(({ name }) => ({
  barFetch: {
    url: `/foos/${name}`,
    query: { foo: verifyFoo(), bar: verifyBar() }
    transform: ({ foos, page }) => ({ bars: foos, page  }),
    then: (foo) => `/bar-for-foos-by-id/${foo.id}`
  }
}))

from react-refetch.

ashtuchkin avatar ashtuchkin commented on May 22, 2024

That's even better! :)

from react-refetch.

hnordt avatar hnordt commented on May 22, 2024

@ryanbrainard,

If you approve the syntax I'll be happy to create a pull request.

from react-refetch.

ryanbrainard avatar ryanbrainard commented on May 22, 2024

To do the data transform, you should be able to use then() on the PromiseState instead of on the request in connect(). The latter will fire off a new request, which is probably not what you want.

from react-refetch.

ryanbrainard avatar ryanbrainard commented on May 22, 2024

@hnordt do you mean call the 'query' attribute 'data' (and maybe also share it with 'body') like jquery does? I wasn't following your example in relation to the issue.

from react-refetch.

ryanbrainard avatar ryanbrainard commented on May 22, 2024

Also, can we please break this into two separate issues? :)

from react-refetch.

hnordt avatar hnordt commented on May 22, 2024

@ryanbrainard I think transforming data on PromiseState is ok, better than add a new prop.

About query. Sorry, I miss typed the verify part. Another example:

connect(({ name }) => ({
  barFetch: {
    url: `/foos/${name}`,
    query: { foo: 'bar', bar: 'foo' }
  }
}))

// barFetch should request /foos/${name}?foo=bar&bar=foo

I think objects are better than raw string for query params because we can do things like this:

{ query: Object.assign({ foo: 'bar' }, { bar: testBar() ? 'foo' : null }) }

from react-refetch.

ashtuchkin avatar ashtuchkin commented on May 22, 2024

Moved discussion of transform functions to #21

from react-refetch.

ryanbrainard avatar ryanbrainard commented on May 22, 2024

I've been thinking about this, and I've decided to decline on this feature for the following reasons:

  1. The query is part of the URL. Having it be in a separate attribute can lead to confusion.
  2. It requires the use of request object syntax. The URL string request syntax should always be preferred for simplicity.
  3. I agree that declaring the query params as an object/hash is good (I do this myself), but I think that converting it to a query string is something that should be done by an explicit function. We could provide something like this in this library, but I'm sure there are several existing libraries that already provide such a facility (e.g. jQuery's $.param()), so I don't think there would be much value in implementing another one. ES6 string templates/interpolation make this even nicer to use to include in a string.

from react-refetch.

Related Issues (20)

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.