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

A Better Implementation #23

Closed
xialvjun opened this issue Nov 16, 2018 · 9 comments
Closed

A Better Implementation #23

xialvjun opened this issue Nov 16, 2018 · 9 comments

Comments

@xialvjun
Copy link

xialvjun commented Nov 16, 2018

import immutagen from "immutagen";

const compose = ({ next, value }) =>
  next
    ? React.cloneElement(value, null, (...args) => compose(next(args)))
    : value;

export function epitath(gen_fn, _this) {
  if (arguments.length < 2) {
    _this = this;
  }
  gen_fn = immutagen(gen_fn.bind(_this));
  return (...args) => compose(gen_fn(...args));
}

That's all!!!
It can avoid creating new Component in every render.

@fakenickels
Copy link
Contributor

Hey @xialvjun, thanks for your suggestion.
Could you explain why have you decided to add this new argument _this to the function arguments?
Also I think this implementation drops class-based components support

Also could you provide a codesandbox link with demos so we can test it quickly?

@xialvjun
Copy link
Author

@eliperelman
Copy link
Contributor

Also I think this implementation drops class-based components support

This has also not been addressed.

@xialvjun
Copy link
Author

what do you mean by drops class-based components support?

@fakenickels
Copy link
Contributor

@eliperelman we delayed indeed to release, it was released now at 1.0.0-beta.2. Sorry the delay.

@fakenickels
Copy link
Contributor

@fakenickels
Copy link
Contributor

Also, we add a "Epitath" wrapper in the component to make easier to see this in the dev tools, see #1

@xialvjun
Copy link
Author

Well, I don't know how to add class-based components support and I don't care about it. Pure Generator Component has meet my needs.

And I didn't add "Epitath" wrapper because this is just a issue, not a PR.

@fakenickels
Copy link
Contributor

Thanks for your suggestions

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

No branches or pull requests

3 participants