-
-
Notifications
You must be signed in to change notification settings - Fork 842
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
feat: add Immer
class
#258
Conversation
That's fast! Quick question, any impact on build size?
Op vr 30 nov. 2018 om 16:53 schreef Alec Larson <notifications@github.com>:
… @aleclarson <https://github.com/aleclarson> requested your review on: #258
<#258> feat: add Immer class.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#258 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhEa2S1iWHSTxkDYo8spQvvngdKY9ks5u0VRfgaJpZM4Y76aN>
.
|
(if it is not too much effort, otherwise will check myself when reviewing)
Op vr 30 nov. 2018 om 17:12 schreef Michel Weststrate <mweststrate@gmail.com
…:
That's fast! Quick question, any impact on build size?
Op vr 30 nov. 2018 om 16:53 schreef Alec Larson ***@***.***
>:
> @aleclarson <https://github.com/aleclarson> requested your review on:
> #258 <#258> feat: add Immer
> class.
>
> —
> You are receiving this because your review was requested.
> Reply to this email directly, view it on GitHub
> <#258 (comment)>, or mute
> the thread
> <https://github.com/notifications/unsubscribe-auth/ABvGhEa2S1iWHSTxkDYo8spQvvngdKY9ks5u0VRfgaJpZM4Y76aN>
> .
>
|
5087bf2
to
7bf1912
Compare
@mweststrate Looks like the UMD bundle went from 8.88KB (3.29KB minified) to 9.8KB (3.56KB minified). Disappointing; I thought this would reduce the size. :( edit: Probably from inflating the |
daad18a
to
c1a548b
Compare
1 similar comment
Tests passing! :) I wonder if the Coveralls bot can be fixed? |
I separated the diff noise out, so you can use 1fc76a7 for easier reviewing. |
Updated the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great PR @aleclarson !
Made some minor comments, but beyond that all LGTM. Thanks a lot!
f8a9777
to
b32804b
Compare
5b0e13b
to
292218a
Compare
f26be43
to
72a681c
Compare
a5abd3d
to
ab05744
Compare
🎉 This PR is included in version 1.9.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Closes #254
Every instance of the
Immer
class provides a boundproduce
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
Renamed
immer.js
toindex.js
so theImmer
class can haveimmer.js
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.
Moved
finalize
logic to theImmer
classInlined the
freeze
function as only one callsite existedInlined the
createState
functions in bothproxy.js
andes5.js
Extract repeated code from
produceEs5
andproduceProxy
(which have sincebeen removed) into the
Immer
classThe
es5.js
andproxy.js
modules now have different exports:scopes
: an array of nestedproduce
calls, where each value is an arrayof unrevoked proxies
currentScope()
: shortcut for getting the last value of thescopes
arraycreateDraft()
: a renamedcreateProxy
with the arguments swappedwillFinalize()
: called right after the recipe function returns (onlyused by ES5 proxies)
Changed some "draft state" properties:
hasCopy
in ES5 state (checking for truthiness ofcopy
does the job)proxy
todraft
in ES5 statefinished
torevoked
in ES5 stateproxies
todrafts
in Proxy staterevoke
method (called by theImmer
class)draft
property to Proxy stateDelay creation of
patches
andinversePatches
arrays until the recipefunction returns. This avoids array allocations when a rollback is performed
by throwing.
Simplified
generatePatches
by removing the last two arguments, since theycan be obtained from the
state
argument.