@@ -21,6 +21,17 @@ const has = Object.prototype.hasOwnProperty
21
21
22
22
const proxies = new WeakMap ( )
23
23
24
+ const blackListedClassMembers = [
25
+ 'constructor' ,
26
+ 'render' ,
27
+ 'componentDidMount' ,
28
+ 'componentWillReceiveProps' ,
29
+ 'componentWillUnmount' ,
30
+
31
+ 'getInitialState' ,
32
+ 'getDefaultProps' ,
33
+ ]
34
+
24
35
const defaultRenderOptions = {
25
36
componentWillReceiveProps : identity ,
26
37
componentWillRender : identity ,
@@ -72,7 +83,9 @@ function createClassProxy(InitialComponent, proxyKey, options) {
72
83
}
73
84
74
85
function proxiedUpdate ( ) {
75
- inject ( this , proxyGeneration , injectedMembers )
86
+ if ( this ) {
87
+ inject ( this , proxyGeneration , injectedMembers )
88
+ }
76
89
}
77
90
78
91
function lifeCycleWrapperFactory ( wrapperName , sideEffect = identity ) {
@@ -87,6 +100,24 @@ function createClassProxy(InitialComponent, proxyKey, options) {
87
100
}
88
101
}
89
102
103
+ function methodWrapperFactory ( wrapperName , realMethod ) {
104
+ return function wrappedMethod ( ...rest ) {
105
+ return realMethod . apply ( this , rest )
106
+ }
107
+ }
108
+
109
+ const fakeBasePrototype = Base =>
110
+ Object . getOwnPropertyNames ( Base )
111
+ . filter ( key => ! blackListedClassMembers . includes ( key ) )
112
+ . filter ( key => {
113
+ const descriptor = Object . getOwnPropertyDescriptor ( Base , key )
114
+ return typeof descriptor . value === 'function'
115
+ } )
116
+ . reduce ( ( acc , key ) => {
117
+ acc [ key ] = methodWrapperFactory ( key , Base [ key ] )
118
+ return acc
119
+ } , { } )
120
+
90
121
const componentDidMount = lifeCycleWrapperFactory (
91
122
'componentDidMount' ,
92
123
target => {
@@ -124,8 +155,9 @@ function createClassProxy(InitialComponent, proxyKey, options) {
124
155
return renderOptions . componentDidRender ( result )
125
156
}
126
157
127
- const defineProxyMethods = Proxy => {
158
+ const defineProxyMethods = ( Proxy , Base = { } ) => {
128
159
defineClassMembers ( Proxy , {
160
+ ...fakeBasePrototype ( Base ) ,
129
161
render : proxiedRender ,
130
162
componentDidMount,
131
163
componentWillReceiveProps,
@@ -139,7 +171,7 @@ function createClassProxy(InitialComponent, proxyKey, options) {
139
171
if ( ! isFunctionalComponent ) {
140
172
ProxyComponent = proxyClassCreator ( InitialComponent , postConstructionAction )
141
173
142
- defineProxyMethods ( ProxyComponent )
174
+ defineProxyMethods ( ProxyComponent , InitialComponent . prototype )
143
175
144
176
ProxyFacade = ProxyComponent
145
177
} else {
@@ -255,6 +287,7 @@ function createClassProxy(InitialComponent, proxyKey, options) {
255
287
} else {
256
288
checkLifeCycleMethods ( ProxyComponent , NextComponent )
257
289
Object . setPrototypeOf ( ProxyComponent . prototype , NextComponent . prototype )
290
+ defineProxyMethods ( ProxyComponent , NextComponent . prototype )
258
291
if ( proxyGeneration > 1 ) {
259
292
injectedMembers = mergeComponents (
260
293
ProxyComponent ,
0 commit comments