-
-
Notifications
You must be signed in to change notification settings - Fork 852
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
[RFC] Export a "produce" factory #254
Comments
ping @mweststrate ICYMI |
@aleclarson I think that is a nice feature! |
aleclarson
added a commit
to aleclarson/immer
that referenced
this issue
Nov 30, 2018
Every instance of the `Immer` class provides a bound `produce` function. As explained in immerjs#254, this class makes room for advanced configuration (if we need it) and allows for interop between Immer-using libraries that have different needs. Here is a summary of the changes Ive made
aleclarson
added a commit
to aleclarson/immer
that referenced
this issue
Nov 30, 2018
Every instance of the `Immer` class provides a bound `produce` function. As explained in immerjs#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.
Merged
aleclarson
added a commit
to aleclarson/immer
that referenced
this issue
Nov 30, 2018
Every instance of the `Immer` class provides a bound `produce` function. As explained in immerjs#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.
aleclarson
added a commit
to aleclarson/immer
that referenced
this issue
Nov 30, 2018
Every instance of the `Immer` class provides a bound `produce` function. As explained in immerjs#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.
aleclarson
added a commit
to aleclarson/immer
that referenced
this issue
Nov 30, 2018
Every instance of the `Immer` class provides a bound `produce` function. As explained in immerjs#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.
aleclarson
added a commit
to aleclarson/immer
that referenced
this issue
Nov 30, 2018
Every instance of the `Immer` class provides a bound `produce` function. As explained in immerjs#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.
aleclarson
added a commit
to aleclarson/immer
that referenced
this issue
Nov 30, 2018
Every instance of the `Immer` class provides a bound `produce` function. As explained in immerjs#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.
aleclarson
added a commit
to aleclarson/immer
that referenced
this issue
Nov 30, 2018
Every instance of the `Immer` class provides a bound `produce` function. As explained in immerjs#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.
aleclarson
added a commit
to aleclarson/immer
that referenced
this issue
Nov 30, 2018
Every instance of the `Immer` class provides a bound `produce` function. As explained in immerjs#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.
aleclarson
added a commit
to aleclarson/immer
that referenced
this issue
Nov 30, 2018
Every instance of the `Immer` class provides a bound `produce` function. As explained in immerjs#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.
aleclarson
added a commit
that referenced
this issue
Nov 30, 2018
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.
aleclarson
added a commit
to aleclarson/immer
that referenced
this issue
Dec 14, 2018
Every instance of the `Immer` class provides a bound `produce` function. As explained in immerjs#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.
aleclarson
added a commit
to aleclarson/immer
that referenced
this issue
Dec 15, 2018
Every instance of the `Immer` class provides a bound `produce` function. As explained in immerjs#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.
aleclarson
added a commit
to aleclarson/immer
that referenced
this issue
Dec 15, 2018
Every instance of the `Immer` class provides a bound `produce` function. As explained in immerjs#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.
aleclarson
added a commit
to aleclarson/immer
that referenced
this issue
Dec 15, 2018
Every instance of the `Immer` class provides a bound `produce` function. As explained in immerjs#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.
aleclarson
added a commit
to aleclarson/immer
that referenced
this issue
Dec 15, 2018
Every instance of the `Immer` class provides a bound `produce` function. As explained in immerjs#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.
aleclarson
added a commit
to aleclarson/immer
that referenced
this issue
Dec 15, 2018
Every instance of the `Immer` class provides a bound `produce` function. As explained in immerjs#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.
🎉 This issue has been resolved in version 1.9.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
new Immer(options)
functionDetails
The
Immer
constructor lets you create aproduce
function with custom behavior and/or hooks.As you can see, there's plenty of room for more configuration, if and when use cases demand it.
This would supplant the need for #221.
The text was updated successfully, but these errors were encountered: