feat: Dropped node 6 support
Before adoption: this commit came in with the history the project adopted, so no landing records it.
BREAKING CHANGE
authored by Michel Weststrate · committed by Alec Larson · parent 17d69c3 · Browse files · 3 files·+3 added−7 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+3 added−7 removed
- tests:+3 added−5 removed
- other:+0 added−2 removed
Provenance
- Commit
eecc773- Tree
4591d23- Author
Michel Weststrate <mweststrate@gmail.com>- Committer
Alec Larson <alec.stanford.larson@gmail.com>- Parent
17d69c3
3 files changed+3 added−7 removed
modified:__tests__/base.js+3 added-5 removed
890 unmodified lines891 }).toThrowErrorMatchingSnapshot()892 })893 })894 895- // TODO: rewrite tests with async/await once node 6 support is dropped895 describe("async recipe function", () => {896 it("can modify the draft", () => {897 const base = {a: 0, b: 0}899- return produce(base, d => {898+ return produce(base, async d => {899 d.a = 1901- return Promise.resolve().then(() => {902- d.b = 1903- })900+ await Promise.resolve()901+ d.b = 1902 }).then(res => {903 expect(res).not.toBe(base)904 expect(res).toEqual({a: 1, b: 1})905 })362 unmodified linesmodified:.travis.yml-1 removed
123345623 unmodified lineslanguage: node_jsnode_js: - "6" - "8" - "10" - "node"env:23 unmodified linesmodified:readme.md-1 removed
661 unmodified lines662 663 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).664 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.665 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.666-1. Some debuggers (at least Node 6 is known) have trouble debugging when Proxies are in play. Node 8 is known to work correctly.666 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)})`667 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.668 669 ## Cool things built with immer138 unmodified lines