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

Support to add additional methods to exclude #3

Open
webbower opened this issue Sep 26, 2016 · 5 comments
Open

Support to add additional methods to exclude #3

webbower opened this issue Sep 26, 2016 · 5 comments

Comments

@webbower
Copy link

Some packages provide mixins (which I know are frowned upon but still unavoidable in certain cases) or subclasses of React.Component that create additional component lifecycle methods. It would be good to allow the addition of other method names to be excluded in the binding to avoid possible weird behavior. Some example libraries I know of (because we use them):

  • React Router (v1 provided a mixin that added a lifecycle method (routerWillLeave). Subsequent versions have changed the pattern).
  • React Meteor Data provides a mixin that adds support for a lifecycle method (getMeteorData) to fetch data from a Meteor backend.

Maybe something like:

autobind.excludeAdditional(['method1', 'method2', ...]) // globally add to REACT_EXCLUDE_METHODS

or

autobind(this, otherProto, { exclude: ['method1', 'method2', ...] }) // for one-off instances

@sstur
Copy link
Member

sstur commented Sep 27, 2016

I totally agree. I'm open to either approach, alhough I like the second one better since it's less global. PR would be welcome.

@webbower
Copy link
Author

@sstur Could be good to support both, although I think it might be better to support the global one if you're going to choose just one. Our site uses React + Meteor so the React Meteor Data mixin method appears a lot and the per-usage pattern would result in a lot of boilerplate. I would assume many people's projects would be like this, having a handful of mixin methods that appear throughout the codebase.

@sstur
Copy link
Member

sstur commented Sep 27, 2016

I'm down with that.

@cakeinpanic
Copy link

I suggest to add 'private method prefix' property
If i want to have private methods and start all of them with underscore for example

@zmorris
Copy link

zmorris commented Nov 10, 2020

I'd prefer to use the more-general class-autobind instead of the more-specific react-autobind, but I don't think I can until a way to exclude or blacklist functions is provided. Here's how they did it, although I think that include and exclude might be better keys than bindOnly and wontBind:

https://github.com/cassiozen/React-autobind#usage

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

4 participants