Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help] Refactor the react-fetches' API - v2.0 #10

Open
dleitee opened this issue Jun 21, 2018 · 1 comment
Open

[Help] Refactor the react-fetches' API - v2.0 #10

dleitee opened this issue Jun 21, 2018 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@dleitee
Copy link
Owner

dleitee commented Jun 21, 2018

Hello folks,

At the first moment, I have created this lib to use internally at CheesecakeLabs, I had never dedicated my totally time to think about the library API.

After launch this I found some errors and equivocals which do not allow the library to grow and scale.

So, it's time to rethink and reorganize the ideas to create a common sense API (v2.0) with your help.

I need your opinion to turn this library more elegant and efficient.

Best regards

@dleitee dleitee changed the title Refactor the react-fetches' API [Help] Refactor the react-fetches' API - v2.0 Jun 21, 2018
@dleitee dleitee added the help wanted Extra attention is needed label Jun 21, 2018
@dleitee
Copy link
Owner Author

dleitee commented Jun 22, 2018

The initial idea for v2.0is to create something like the ApolloClient.

We will have two components Request and Dispatcher:

<Request uri="friends" method="GET">
  {({ loading, error, data }) => {
    if (loading) {
      return "Loading..."
    }
    if (error) {
      return `Error: ${error.message}`
    }

     return (
        <select name="friend" onChange={onFriendSelected}>
          {data.friends.map(friend => (
            <option key={friend.id} value={friend.id}>
              {friend.name}
            </option>
          ))}
        </select>
      )
  }}
</Request>

and

<Dispatcher method="POST" uri="friend">
  {(addFriend, { loading, error, data }) => {
    if (loading) {
       return "Saving..."
    }
    return (
       <Fragment>
           <button onClick={() => addFriend({ name: 'John Clue'})}>Save</button>
           {error? (<span>Error: {error.message}</span>): null}
      </Fragment>
    )
  }}
</Dispatcher>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant