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

Regenerate overridden members #837

Merged
merged 1 commit into from
Feb 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
2 changes: 1 addition & 1 deletion packages/react-stand-in/src/createClassProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ function createClassProxy(InitialComponent, proxyKey, wrapResult = identity) {

isFunctionalComponent = !isReactClass(NextComponent)
proxyGeneration++
injectedMembers = {}

// Save the next constructor so we call it
const PreviousComponent = CurrentComponent
Expand Down Expand Up @@ -222,6 +221,7 @@ function createClassProxy(InitialComponent, proxyKey, wrapResult = identity) {
NextComponent,
InitialComponent,
lastInstance,
injectedMembers,
)
}
}
Expand Down
7 changes: 6 additions & 1 deletion packages/react-stand-in/src/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function mergeComponents(
NextComponent,
InitialComponent,
lastInstance,
injectedMembers,
) {
const injectedCode = {}
try {
Expand Down Expand Up @@ -79,7 +80,11 @@ function mergeComponents(
}

const nextString = String(nextAttr)
if (nextString !== String(prevAttr)) {
const injectedBefore = injectedMembers[key]
if (
nextString !== String(prevAttr) ||
(injectedBefore && nextString !== String(injectedBefore))
) {
if (!hasRegenerate) {
if (
nextString.indexOf('function') < 0 &&
Expand Down
51 changes: 51 additions & 0 deletions packages/react-stand-in/test/consistency.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,57 @@ describe('consistency', () => {

expect(Proxy.prototype instanceof Bar).toBe(true)
})

it('should revert arrow member change', () => {
/* eslint-disable */
class BaseClass extends React.Component {
arrow = () => 42

render() {
return this.arrow()
}

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

class Update1Class extends React.Component {
arrow = () => 43

render() {
return this.arrow()
}

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

class Update2Class extends React.Component {
arrow = () => 42

render() {
return this.arrow()
}

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

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

proxy.update(Update1Class)
expect(instance.render()).toBe(43)

proxy.update(Update2Class)
expect(instance.render()).toBe(42)
})
})
})

Expand Down