react-class-binder icon indicating copy to clipboard operation
react-class-binder copied to clipboard

How does this handle child classes?

Open jamesaspence opened this issue 8 years ago • 7 comments

Hi!

I was just wondering if I had to add the binder mixin on child classes. Let's say I have an abstract parent classes that extends React.Component, then children that derive. Do I need to add the binder mixin to the children as well as the parents, or just the parent?

jamesaspence avatar Sep 11 '16 15:09 jamesaspence

This module is very careful to only apply to the "current" class.

That means that you will need to apply it to every single class you want to use it in, regardless of if it extends a class that has it applied.

This was to prevent any issues overwriting this for classes you extend.

Klathmon avatar Sep 11 '16 15:09 Klathmon

Thanks for the quick response.

I'm running into issues binding a child class where I extend a generic parent component.

My parent looks something like this:

export default class DataComponent extends binder(React.Component) {
    getRepository(): void { // }
}

Child:

export default class ChildComponent extends binder(DataComponent) {
    onChildComponent(component) {
        this.component = component;
    }
    //
}

However, I had an error on onChildComponent - this was undefined.

Any ideas? I'm binding both parent and child classes.

jamesaspence avatar Sep 24 '16 03:09 jamesaspence

Ugh, honestly I'm not sure... I'm actually on vacation for a week currently, so I won't be able to look at this until like Oct 3rd or later.

I'll reopen this for now.

Klathmon avatar Sep 24 '16 07:09 Klathmon

Sure thing. For now I'm just not using the parent. Let me know when you get back if you want to see the exact code, I have it hosted and can share.

jamesaspence avatar Sep 26 '16 15:09 jamesaspence

Bump? Any movement on this?

jamesaspence avatar Oct 22 '16 15:10 jamesaspence

Sorry, but not really. I looked into what is going on and I can't seem to pinpoint why it's not working. I think there is some interaction with the prototypes that i'm not understanding.

Klathmon avatar Oct 22 '16 16:10 Klathmon

Hmm okay. Maybe if I get a chance I'll dig in, take a look for myself? If I do I'll be sure to submit a PR!

jamesaspence avatar Oct 24 '16 14:10 jamesaspence