Skip to content

Commit

Permalink
feat: Dropped node 6 support
Browse files Browse the repository at this point in the history
BREAKING CHANGE
  • Loading branch information
mweststrate authored and aleclarson committed Apr 17, 2019
1 parent 17d69c3 commit eecc773
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js:
- "6"
- "8"
- "10"
- "node"
Expand Down
8 changes: 3 additions & 5 deletions __tests__/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,15 +892,13 @@ function runBaseTest(name, useProxies, autoFreeze, useListener) {
})
})

// TODO: rewrite tests with async/await once node 6 support is dropped
describe("async recipe function", () => {
it("can modify the draft", () => {
const base = {a: 0, b: 0}
return produce(base, d => {
return produce(base, async d => {
d.a = 1
return Promise.resolve().then(() => {
d.b = 1
})
await Promise.resolve()
d.b = 1
}).then(res => {
expect(res).not.toBe(base)
expect(res).toEqual({a: 1, b: 1})
Expand Down
1 change: 0 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,6 @@ console.log(increment(base).counter) // 1
1. Don't redefine draft like, `draft = myCoolNewState`. Instead, either modify the `draft` or return a new state. See [Returning data from producers](#returning-data-from-producers).
1. Immer assumes your state to be a unidirectional tree. That is, no object should appear twice in the tree, and there should be no circular references.
1. Since Immer uses proxies, reading huge amounts of data from state comes with an overhead (especially in the ES5 implementation). If this ever becomes an issue (measure before you optimize!), do the current state analysis before entering the producer function or read from the `currentState` rather than the `draftState`. Also, realize that immer is opt-in everywhere, so it is perfectly fine to manually write super performance critical reducers, and use immer for all the normal ones. Also note that `original` can be used to get the original state of an object, which is cheaper to read.
1. Some debuggers (at least Node 6 is known) have trouble debugging when Proxies are in play. Node 8 is known to work correctly.
1. Always try to pull `produce` 'up', for example `for (let x of y) produce(base, d => d.push(x))` is exponentially slower than `produce(base, d => { for (let x of y) d.push(x)})`
1. It is possible to return values from producers, except, it is not possible to return `undefined` that way, as it is indistinguishable from not updating the draft at all! If you want to replace the draft with `undefined`, just return `nothing` from the producer.

Expand Down

0 comments on commit eecc773

Please sign in to comment.