-
-
Notifications
You must be signed in to change notification settings - Fork 874
Fix: Cannot set property of which has only a getter #438
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
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c4f4431
Fix: Cannot set property of which has only a getter
dalcib c917579
Merge pull request #1 from dalcib/dalcib-patch-1
dalcib 61f7a49
Includes semicólon
dalcib f7c833d
Includes tests
dalcib c2764f9
Replace !ownKeys for !Object.keys
dalcib 5dd0e7e
Rebase to 5.0
dalcib 060dae9
Merge branch 'dalcib-patch-1' into master
dalcib 90dfe93
Merge branch 'master' into dalcib-patch-1
dalcib 2409fe5
Update 5.0.0
dalcib 171389b
Merge branch 'dalcib-patch-1' into master
dalcib e4aa16b
Merge pull request #2 from dalcib/master
dalcib e4c32ba
Fix duplicate code
dalcib e88b970
remove blank line
dalcib 0331918
Merge pull request #3 from immerjs/master
dalcib 439ce1b
Solve setter
dalcib 7ef0389
Fi setter 2
dalcib File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,30 @@ | ||
| { | ||
| // Use IntelliSense to learn about possible attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| // Note; this config requires node 8.4 or higher | ||
| "type": "node", | ||
| "protocol": "auto", | ||
| "request": "launch", | ||
| "name": "debug unit test", | ||
| "stopOnEntry": false, | ||
| "program": "${workspaceRoot}/node_modules/jest-cli/bin/jest.js", | ||
| "args": ["--verbose", "--testRegex",".*", "-i", "${file}"], | ||
| "runtimeArgs": [ | ||
| "--nolazy" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| // Use IntelliSense to learn about possible attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "type": "node", | ||
| "name": "vscode-jest-tests", | ||
| "request": "launch", | ||
| "program": "${workspaceFolder}/node_modules/jest/bin/jest", | ||
| "args": ["--runInBand", "my"], | ||
| "cwd": "${workspaceFolder}", | ||
| "console": "integratedTerminal", | ||
| "internalConsoleOptions": "neverOpen", | ||
| "disableOptimisticBPs": true | ||
| }, | ||
| { | ||
| // Note; this config requires node 8.4 or higher | ||
| "type": "node", | ||
| "protocol": "auto", | ||
| "request": "launch", | ||
| "name": "debug unit test", | ||
| "stopOnEntry": false, | ||
| "program": "${workspaceRoot}/node_modules/jest-cli/bin/jest.js", | ||
| "args": ["--verbose", "--testRegex", ".*", "-i", "${file}"], | ||
| "runtimeArgs": ["--nolazy"] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import produce, {immerable, setUseProxies} from "../src/index" | ||
|
|
||
| setUseProxies(true) | ||
|
|
||
| describe("class with getters and methods", () => { | ||
| class State { | ||
| constructor() { | ||
| this[immerable] = true | ||
| this.word1 = "bar" | ||
| this.word2 = "foo" | ||
| this.foo = 0 | ||
| this._bar = {baz: 1} | ||
| } | ||
| get chars() { | ||
| return this.word1.split("") | ||
| } | ||
| //set chars(v) {} | ||
| get bar() { | ||
| return this._bar | ||
| } | ||
| set barr(v) { | ||
| this.foo = v | ||
| console.log(v, "sdffs") | ||
| } | ||
| get barr() {} | ||
| setWord2() { | ||
| let mix = [...this.chars].slice(0, 3) | ||
| mix[2] = "z" | ||
| this.word2 = mix.join("") | ||
| } | ||
| syncFoo() { | ||
| return produce(this, state => { | ||
| state.foo = state.bar.baz | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| const state = new State() | ||
|
|
||
| it("should work without creating a proxy for a getter property", () => { | ||
| expect(state.chars).toEqual(["b", "a", "r"]) | ||
| const newState1 = produce(state, d => { | ||
| d.setWord2() | ||
| }) | ||
| const newState3 = produce(state, d => { | ||
| d.barr = 2 | ||
| }) | ||
| expect(newState1.word2).toEqual("baz") | ||
| //expect(newState3.foo).toEqual(2) | ||
|
|
||
| /* expect(state.bar).toEqual({baz: 1}) | ||
| const newState2 = state.syncFoo() | ||
| expect(newState2.foo).toEqual(1) | ||
| expect(newState2.bar).toEqual({baz: 1}) */ | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.