Skip to content

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

Merged
rorticus merged 4 commits into
dojo:masterfrom
rorticus:bind-james-bind
May 29, 2019
Merged

Fixing a problem with auto-bind and multiple subclasses#348
rorticus merged 4 commits into
dojo:masterfrom
rorticus:bind-james-bind

Conversation

@rorticus
Copy link
Copy Markdown
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.

@rorticus rorticus requested review from agubler and matt-gadd May 20, 2019 23:11
}

const IGNORE_LIST: (string | symbol)[] = ['constructor', 'render'];
const IGNORE_LIST: (string | symbol)[] = ['render', ...Object.getOwnPropertyNames(Object.getPrototypeOf({}))];
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/widget-core/WidgetBase.ts Outdated
if (autoBindCache.has(prototype)) {
keys = autoBindCache.get(prototype) as string[];
} else {
let p = prototype;
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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