Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/createClassProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,10 @@ function proxyClass(InitialComponent) {
}

let displayName = getDisplayName(InitialComponent);
try {
// Create a proxy constructor with matching name
ProxyComponent = new Function('factory', 'instantiate',
`return function ${displayName}() {
return instantiate(factory, this, arguments);
}`
)(() => CurrentComponent, instantiate);
} catch (err) {
// Some environments may forbid dynamic evaluation
ProxyComponent = function () {
return instantiate(() => CurrentComponent, this, arguments);
};
}
ProxyComponent = function DynamicProxyComponent() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please add some tests to show what problem it solves?

Choose a reason for hiding this comment

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

It's useful for HOCs to wrap the displayName of the base component, for example HigherOrderComponent(BaseComponent). This is not a valid function name however, which causes unnecessary errors to be thrown.

return instantiate(() => CurrentComponent, this, arguments);
};
// Fix-up: the DynamicProxyComponent name should reflect the inner component
try {
Object.defineProperty(ProxyComponent, 'name', {
value: displayName
Expand Down