andreypopp / autobind-decorator

Decorator to automatically bind methods to class instances
MIT License
1.45k stars 66 forks source link

[PROPOSAL] Ability to unbind some method #20

Closed Johnius closed 8 years ago

Johnius commented 8 years ago

Would be nice to have an ability to unbind some special functions from instance. Make it static.

cpsubrian commented 8 years ago

@Johnius Thinking my PR #27 solves this for you.

Johnius commented 8 years ago

@cpsubrian It looks working but I think you'll face problems when your class will get grow. I think still would be sweet to have @unbind and use it on specific methods. Maybe you have some thoughts about why it might be good or bad—about your and my idea.

cpsubrian commented 8 years ago

@Johnius I can't speak to your use case, but I'm always in one of three situations:

  1. You want most of your methods autobound, and few not bound.
    • The ones you don't want bound usually follow a semantic pattern (i.e. 'render', 'component*')
  2. You want to routinely bind only methods that follow a semantic pattern (i.e. 'handle', 'on')
  3. You only want to bind a few specific methods
    • In this case just use @autobind on those methods

I would personally find a mix of @autobind and @unbind hard to follow/remember. But my main use-case is either React components or custom 'Model' classes. Both of these follow repeatable patterns.

I wonder what your use case is for a large class that wants a scattering of methods unbound. If I understood that better I could weigh in on it :smile:

stevemao commented 8 years ago

see #27