Skip to content

Commit

Permalink
Documented 1.0.0 release!
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Jan 31, 2018
1 parent 7d2148c commit 5e16b30
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
15 changes: 15 additions & 0 deletions __tests__/readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,19 @@ describe("readme example", () => {
// 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)
})
})
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# 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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "immer",
"version": "0.8.5",
"version": "1.0.0",
"description": "Create your next immutable state by mutating the current one",
"main": "dist/immer.js",
"umd:main": "dist/immer.umd.js",
Expand Down
29 changes: 27 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,39 @@ const byId = produce((draft, action) => {
Note that `state` is now factored out (the created reducer will accept a state, and invoke the bound producer with it).
One think to keep in mind; you cannot use this construction to initialize an uninitialized state. E.g. `draft = {}` doesn't do anything useful.


## Auto freezing

Immer automatically freezes any state trees that are modified using `produce`.
This protects against accidental modifications of the state tree outside of a producer.
This comes with a performance impact, so it is recommended to disable this option in production.
It is by default enabled.
Use `setAutoFreeze(true / false)` to turn this feature on or off.
By default it is turned on during local development, and turned off in production.
Use `setAutoFreeze(true / false)` to explicitly turn this feature on or off.

## Using `this`

The recipe will be always invoked with the `draft` as `this` context.

This means that the following constructions are also valid:

```javascript
const base = { counter: 0 }

const next = produce(base, function() {
this.counter++
})
console.log(next.counter) // 1

// OR
const increment = produce(function() {
this.counter++
})
console.log(increment(base).counter) // 1
```

## TypeScript or Flow

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.

## Immer on older JavaScript environments?

Expand Down Expand Up @@ -216,6 +240,7 @@ Use `yarn test:perf` to reproduce them locally.
![performance.png](images/performance.png)

Some observations:
* 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.
* 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).
* 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.
* Immer with proxies is roughly speaking twice as slow as a hand written reducer. This is in practice negligible.
Expand Down

0 comments on commit 5e16b30

Please sign in to comment.