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

Fixing a problem with auto-bind and multiple subclasses #348

Merged
merged 4 commits into from
May 29, 2019

Conversation

rorticus
Copy link
Contributor

Type: bug

The following has been addressed in the PR:

Description:

There is a problem with the new auto-bind code when there are multiple levels of inheritance. It currently only applies the binding logic to the first level of inheritance.

To fix this, we're walking the prototype chain up to WidgetBase and gathering all the properties from there. Since this is a bit of an expensive operation, we're also caching the result of the property gathering so it only needs to happen once per widget class.

@@ -52,15 +52,38 @@ function isDomMeta(meta: any): meta is Base {
return Boolean(meta.afterRender);
}

const IGNORE_LIST: (string | symbol)[] = ['constructor', 'render'];
const IGNORE_LIST: (string | symbol)[] = ['render', ...Object.getOwnPropertyNames(Object.getPrototypeOf({}))];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can exclude all the properties that come from Object.prototype. Technically we might not even need this since we break our loop on subclasses of WidgetBase?

p = Object.getPrototypeOf(p);
}

keys = keys.filter((k) => typeof instance[k] === 'function' && IGNORE_LIST.indexOf(k) === -1);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filtering of keys through the ignore list is now done up here rather than down yonder.

if (autoBindCache.has(prototype)) {
keys = autoBindCache.get(prototype) as string[];
} else {
let p = prototype;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to do this, just use prototype?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rorticus Did you see this? ^

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed extra variable p!

@agubler
Copy link
Member

agubler commented May 28, 2019

@rorticus It also looks like CI is failing

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

Successfully merging this pull request may close these issues.

2 participants