Skip to content
Myr

fixed conflicts

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Gregory Assasie · committed by Gregory Assasie · parents 347259d, 4d4b1c9 · Browse files · 4 files+21 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+21 added−11 removed

  • other:+21 added−11 removed

4 files+21 added−11 removed

modified:changelog.md+8 added
modified:immer.js+4 added-4 removed
59 unmodified lines
60 deleteProperty(target, property) {61 const copy = getOrCreateCopy(target)62 delete copy[property]63 return true64 },64 }65 }6667 // creates a copy for a base object if there ain't one68 function getOrCreateCopy(base) {
31 unmodified lines
100 : Object.assign({}, base)101 Object.defineProperty(proxyTarget, CLONE_TARGET, {102 enumerable: false,103 value: base,104 configurable: true,104 configurable: true105 })106 } else {107 proxyTarget = base108 }
57 unmodified lines
166 const maybeVoidReturn = thunk(rootClone)167 //values either than undefined will trigger warning;168 !Object.is(maybeVoidReturn, undefined) &&169 console.warn(170 `Immer callback expects no return value. However ${typeof maybeVoidReturn} was returned`,170 `Immer callback expects no return value. However ${typeof maybeVoidReturn} was returned`171 )172 // console.log(`proxies: ${revocableProxies.size}, copies: ${copies.size}`)173 // revoke all proxies174 revoke(revocableProxies)
41 unmodified lines
216 autoFreeze = enableAutoFreeze217}218219Object.defineProperty(exports, "__esModule", {220 value: true,220 value: true221})222module.exports.default = immer223module.exports.setAutoFreeze = setAutoFreeze
modified:package.json+3 added-2 removed
modified:readme.md+6 added-5 removed
3 unmodified lines
45---67Immer (German for: always) is a tiny package that allows you to work with immutable state in a more convenient way.8It is based on [_copy-on-write_](https://en.wikipedia.org/wiki/Copy-on-write) mechanism.8It is based on the [_copy-on-write_](https://en.wikipedia.org/wiki/Copy-on-write) mechanism.910The basic idea is that, you will apply all your changes to a _draftState_, which is a proxy of the _currentState_ and once all your mutations are completed, immer will produce the _nextState_ based on the mutations to the draft state. This means that you can interact with your data by simply modifying it, while keeping all the benefits of immutable data.10The basic idea is that you will apply all your changes to a temporarily _draftState_, which is a proxy of the _currentState_.11Once all your mutations are completed, immer will produce the _nextState_ based on the mutations to the draft state.12This means that you can interact with your data by simply modifying it, while keeping all the benefits of immutable data.1312<center>1314![immer.png](immer.png)1516Using immer is like having a personal assistant; he takes a letter (the current state), and gives you a copy (draft) to jot changes onto. Once you are done, the assistant will take your draft and produce the real immutable, final letter for you (the next state).17</center>1718A mindful reader might notice that this is quite similar to `withMutations` of ImmutableJS. It is indeed, but generalized and applicable to plain, native JavaScript data structures (arrays and objects) without further needing any library.1920## API2122The immer package exposes a single function:23
160 unmodified lines