Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: always update bound functions. #949 #950

Merged
merged 1 commit into from
May 1, 2018
Merged
Show file tree
Hide file tree
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
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