Skip to content

Commit

Permalink
fix: always update bound functions. #949
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Apr 29, 2018
1 parent 949f859 commit 7819c71
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/proxy/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ function mergeComponents(

const nextString = String(nextAttr)
const injectedBefore = injectedMembers[key]
const isFunction =
nextString.indexOf('function') >= 0 || nextString.indexOf('=>') >= 0
if (
nextString !== String(prevAttr) ||
(injectedBefore && nextString !== String(injectedBefore))
(injectedBefore && nextString !== String(injectedBefore)) ||
isFunction
) {
if (!hasRegenerate) {
if (
nextString.indexOf('function') < 0 &&
nextString.indexOf('=>') < 0
) {
if (!isFunction) {
// just copy prop over
injectedCode[key] = nextAttr
} else {
Expand All @@ -106,6 +106,8 @@ function mergeComponents(
} else {
injectedCode[key] = nextAttr
}
} else {
// key was skipped
}
}
})
Expand Down
40 changes: 40 additions & 0 deletions test/proxy/consistency.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,46 @@ describe('consistency', () => {
expect(instance.render()).toBe(42)
})

it('should reflect external dependencies', () => {
/* eslint-disable */
const externalValue = 42
class BaseClass extends React.Component {
arrow = () => externalValue

render() {
return this.arrow()
}

__reactstandin__regenerateByEval(key, code) {
this[key] = eval(code)
}
}

const proxy = createProxy(BaseClass)
const Proxy = proxy.get()
const instance = new Proxy()
expect(instance.render()).toBe(42)

{
const externalValue = 24
class Update1Class extends React.Component {
arrow = () => externalValue

render() {
return this.arrow()
}

__reactstandin__regenerateByEval(key, code) {
this[key] = eval(code)
}
}
proxy.update(Update1Class)
}
/* eslint-enable */

expect(instance.render()).toBe(24)
})

it('should stand-for all class members', () => {
class Initial {
constructor() {
Expand Down

0 comments on commit 7819c71

Please sign in to comment.