Skip to content

Commit a8b687a

Browse files
committed
fix: always update bound functions. #949
1 parent 949f859 commit a8b687a

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

src/proxy/inject.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ function mergeComponents(
8181

8282
const nextString = String(nextAttr)
8383
const injectedBefore = injectedMembers[key]
84+
const isFunction =
85+
nextString.indexOf('function') >= 0 || nextString.indexOf('=>') >= 0
8486
if (
8587
nextString !== String(prevAttr) ||
86-
(injectedBefore && nextString !== String(injectedBefore))
88+
(injectedBefore && nextString !== String(injectedBefore)) ||
89+
isFunction
8790
) {
8891
if (!hasRegenerate) {
89-
if (
90-
nextString.indexOf('function') < 0 &&
91-
nextString.indexOf('=>') < 0
92-
) {
92+
if (!isFunction) {
9393
// just copy prop over
9494
injectedCode[key] = nextAttr
9595
} else {
@@ -106,6 +106,8 @@ function mergeComponents(
106106
} else {
107107
injectedCode[key] = nextAttr
108108
}
109+
} else {
110+
//console.warn('skipped',key, nextString);
109111
}
110112
}
111113
})

test/proxy/consistency.test.js

+41
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,47 @@ describe('consistency', () => {
264264
expect(instance.render()).toBe(42)
265265
})
266266

267+
it('should reflect external dependencies', () => {
268+
/* eslint-disable */
269+
const externalValue = 42
270+
class BaseClass extends React.Component {
271+
arrow = () => externalValue
272+
273+
render() {
274+
return this.arrow()
275+
}
276+
277+
__reactstandin__regenerateByEval(key, code) {
278+
this[key] = eval(code)
279+
}
280+
}
281+
282+
/* eslint-enable */
283+
284+
const proxy = createProxy(BaseClass)
285+
const Proxy = proxy.get()
286+
const instance = new Proxy()
287+
expect(instance.render()).toBe(42)
288+
289+
{
290+
const externalValue = 24
291+
class Update1Class extends React.Component {
292+
arrow = () => externalValue
293+
294+
render() {
295+
return this.arrow()
296+
}
297+
298+
__reactstandin__regenerateByEval(key, code) {
299+
this[key] = eval(code)
300+
}
301+
}
302+
proxy.update(Update1Class)
303+
}
304+
305+
expect(instance.render()).toBe(24)
306+
})
307+
267308
it('should stand-for all class members', () => {
268309
class Initial {
269310
constructor() {

0 commit comments

Comments
 (0)