Documented 1.0.0 release!
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Michel Weststrate · committed by Michel Weststrate · parent 7d2148c · Browse files · 4 files·+50 added−3 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+50 added−3 removed
- tests:+15 added−0 removed
- other:+35 added−3 removed
Provenance
- Commit
5e16b30- Tree
59640cb- Author
Michel Weststrate <mweststrate@gmail.com>- Committer
Michel Weststrate <mweststrate@gmail.com>- Parent
7d2148c
4 files changed+50 added−3 removed
modified:__tests__/readme.js+15 added
31 unmodified lines323334353637383940414243444546474849505131 unmodified lines expect(nextState[0]).toBe(baseState[0]) // changed data not (dûh) expect(nextState[1]).not.toBe(baseState[1]) })
it("it can use this", () => { const base = {counter: 0}
const next = produce(base, function() { this.counter++ }) expect(next.counter).toBe(1)
// OR const increment = produce(function() { this.counter++ }) expect(increment(base).counter).toBe(1) })})modified:changelog.md+7 added
12345678910111213103 unmodified linesExpand all# Changelog
### 1.0.0 (31-Jan-2018)
* Producer functions will now always be invoked with the draft as context (`this`). See the [readme](https://github.com/mweststrate/immer#using-this).* Freezing the data will now be automatically (by default) be disabled in production builds. By [Gregory Assasie](https://github.com/Gregjarvez)* Fixed Flow typings. Fixes [#80](https://github.com/mweststrate/immer/issues/80). By [Marcin Szczepanski](https://github.com/mweststrate/immer/issues?q=is%3Apr+author%3Amarcins) in [#85](https://github.com/mweststrate/immer/pull/85)* Fixed issue where constructor type was not preserved. By [iruca3](https://github.com/iruca3) through [#81](https://github.com/mweststrate/immer/pull/81)
### 0.8.5
* Immer will automatically turn auto-freezing of in production. Use `setAutoFreeze` to manually control it. See [#46](https://github.com/mweststrate/immer/issues/78), [#76](https://github.com/mweststrate/immer/pull/76)* Fixed issue where objects were unnecessary proxied, causing exceptions. See [#78](https://github.com/mweststrate/immer/issues/78)103 unmodified linesExpand allmodified:package.json+1 added-1 removed
1 {2 "name": "immer",3- "version": "0.8.5",3+ "version": "1.0.0",4 "description": "Create your next immutable state by mutating the current one",5 "main": "dist/immer.js",6 "umd:main": "dist/immer.umd.js",7 "module": "dist/immer.module.js",72 unmodified linesmodified:readme.md+27 added-2 removed
173 unmodified lines174 175 Note that `state` is now factored out (the created reducer will accept a state, and invoke the bound producer with it).176 One think to keep in mind; you cannot use this construction to initialize an uninitialized state. E.g. `draft = {}` doesn't do anything useful.177 178-178 ## Auto freezing179 180 Immer automatically freezes any state trees that are modified using `produce`.181 This protects against accidental modifications of the state tree outside of a producer.182 This comes with a performance impact, so it is recommended to disable this option in production.183 It is by default enabled.185- Use `setAutoFreeze(true / false)` to turn this feature on or off.184 By default it is turned on during local development, and turned off in production.185+ Use `setAutoFreeze(true / false)` to explicitly turn this feature on or off.186 187+## Using `this`188+189+The recipe will be always invoked with the `draft` as `this` context.190+191+This means that the following constructions are also valid:192+193+```javascript194+const base = { counter: 0 }195+196+const next = produce(base, function() {197+ this.counter++198+})199+console.log(next.counter) // 1200+201+// OR202+const increment = produce(function() {203+ this.counter++204+})205+console.log(increment(base).counter) // 1206+```207+208+## TypeScript or Flow209+210+The Immer package ships with type definitions inside the package, which should be picked up by TypeScript and Flow out of the box and without further configuration.211+212 ## Immer on older JavaScript environments?213 214 By default `produce` tries to use proxies for optimal performance.215 However, on older JavaScript engines `Proxy` is not available.23 unmodified lines239 240 241 242 Some observations:243+* From `immer` perspective, this benchmark is a _worst case_ scenario, because the root collection it has to proxy is really large relatively to the rest of the data set.244 * The _mutate_, and _deepclone, mutate_ benchmarks establish a baseline on how expensive changing the data is, without immutability (or structural sharing in the deep clone case).245 * The _reducer_ and _naive reducer_ are implemented in typical Redux style reducers. The "smart" implementation slices the collection first, and then maps and freezes only the relevant todos. The "naive" implementation just maps over and processes the entire collection.246 * Immer with proxies is roughly speaking twice as slow as a hand written reducer. This is in practice negligible.247 * Immer is roughly as fast as ImmutableJS. However, the _immutableJS + toJS_ makes clear the cost that often needs to be paid later; converting the immutableJS objects back to plain objects, to be able to pass them to components, over the network etc... (And there is also the upfront cost of converting data received from e.g. the server to immutable JS)42 unmodified lines