-
-
Notifications
You must be signed in to change notification settings - Fork 852
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Every instance of the `Immer` class provides a bound `produce` function. As explained in #254, this class makes room for advanced configuration (if we need it) and allows for interop between Immer-using libraries that have different needs. I took the time to refactor while I was implementing this, so the diff may look more overwhelming than it is. :) Summary: 1. Renamed `immer.js` to `index.js` so the `Immer` class can have `immer.js` 2. Use the word "draft" in place of "proxy" in most places, because "draft" is a higher level of abstraction. It also makes sense to use the same semantics both internally and externally. 3. Moved `finalize` logic to the `Immer` class 4. Inlined the `freeze` function as only one callsite existed 5. Inlined the `createState` functions in both `proxy.js` and `es5.js` 6. Extract repeated code from `produceEs5` and `produceProxy` (which have since been removed) into the `Immer` class 7. The `es5.js` and `proxy.js` modules now have different exports: - `scopes`: an array of nested `produce` calls, where each value is an array of unrevoked proxies - `currentScope()`: shortcut for getting the last value of the `scopes` array - `createDraft()`: a renamed `createProxy` with the arguments swapped - `willFinalize()`: called right after the recipe function returns (only used by ES5 proxies) 8. Changed some "draft state" properties: - removed `hasCopy` in ES5 state (checking for truthiness of `copy` does the job) - renamed `proxy` to `draft` in ES5 state - renamed `finished` to `revoked` in ES5 state - renamed `proxies` to `drafts` in Proxy state - added `revoke` method (called by the `Immer` class) - added `draft` property to Proxy state - use null literals instead of undefined 9. Delay creation of `patches` and `inversePatches` arrays until the recipe function returns. This avoids array allocations when a rollback is performed by throwing. 10. Simplified `generatePatches` by removing the last two arguments, since they can be obtained from the `state` argument.
- Loading branch information
1 parent
66e51e1
commit ecd04dc
Showing
11 changed files
with
400 additions
and
454 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
Oops, something went wrong.