Skip to content

Commit 7819c71

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

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-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+
// key was skipped
109111
}
110112
}
111113
})

test/proxy/consistency.test.js

+40
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,46 @@ 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+
const proxy = createProxy(BaseClass)
283+
const Proxy = proxy.get()
284+
const instance = new Proxy()
285+
expect(instance.render()).toBe(42)
286+
287+
{
288+
const externalValue = 24
289+
class Update1Class extends React.Component {
290+
arrow = () => externalValue
291+
292+
render() {
293+
return this.arrow()
294+
}
295+
296+
__reactstandin__regenerateByEval(key, code) {
297+
this[key] = eval(code)
298+
}
299+
}
300+
proxy.update(Update1Class)
301+
}
302+
/* eslint-enable */
303+
304+
expect(instance.render()).toBe(24)
305+
})
306+
267307
it('should stand-for all class members', () => {
268308
class Initial {
269309
constructor() {

0 commit comments

Comments
 (0)