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

Is it possible to yield all the arguments without having to wrap component? #24

Open
yantakus opened this issue Nov 20, 2018 · 3 comments
Labels
enhancement New feature or request

Comments

@yantakus
Copy link

yantakus commented Nov 20, 2018

Having to do this:

const MutationWrapper = ({ children, ...props }) =>
  <Mutation {...props}>{(mutate, result) => children({ mutate, result })}</Mutation>

const { mutate, result } = yield <MutationWrapper />

when you want to access all arguments (and it's always the case with Mutation) negotiates the main benefit of epitath (at least for me) - conciseness.

I tried to read the code and understand if it is possible to return all the arg by default, but unfortunately I failed to do this quickly, so I decided to open this thread.

@yantakus
Copy link
Author

yantakus commented Nov 20, 2018

What if we return our arguments as array? Something like this:

const MutationWrapper = ({ children, ...props }) => (
  <Mutation {...props}>
    {(...args) => children(args)}
  </Mutation>
)

const [mutation, { loading }] = yield (<Mutation mutation={SOME_MUTATION} />)

And in case of using a component that returns a single argument it would be:

const [{ data, loading }] = yield (
  <Query query={SOME_QUERY} />
)

instead of

const { data, loading } = yield (
  <Query query={SOME_QUERY} />
)

I know this is a breaking change, but it would work for all use cases out of the box, without having to create wrappers for components with multiple arguments.

@fakenickels fakenickels added the enhancement New feature or request label Nov 21, 2018
@fakenickels
Copy link
Contributor

Hey, thanks for bringing this up @yantakus.
This was actually discussed at #1, but indeed, I think making the args an array would some all the problems at once.
We can probably make it the only way to use it.
The reason why it only passes the first argument is that we wanted to make the API surface as simple as possible.

@fakenickels
Copy link
Contributor

Much in agree with this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants