readme.js
This file
Path
__tests__/readme.js
36 lines · 992 bytes · JavaScript
Last changed by
transpile es5 codeMichel Weststratebefore adoptionf012154
History of this fileTake it
Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 1why, one step back1"use strict"transpile es5 codeMichel Weststratebefore adoptionf012154
line 2why, one step back2import produce from "../src/immer"Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
lines 3–8why, one step back34describe("readme example", () => {5 it("works", () => {6 const baseState = [7 {8 todo: "Learn typescript",No trailing commas, might break babel, fixes #21Michel Weststratebefore adoption2a1da31
line 9why, one step back9 done: trueMerge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
lines 10–12why, one step back10 },11 {12 todo: "Try immer",No trailing commas, might break babel, fixes #21Michel Weststratebefore adoption2a1da31
lines 13–14why, one step back13 done: false14 }Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
lines 15–16why, one step back15 ]16`immer` -> `produce`. Implements #24Michel Weststratebefore adoptione3eacea
line 17why, one step back17 const nextState = produce(baseState, draft => {Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
lines 18–36why, one step back18 draft.push({todo: "Tweet about it"})19 draft[1].done = true20 })2122 // the new item is only added to the next state,23 // base state is unmodified24 expect(baseState.length).toBe(2)25 expect(nextState.length).toBe(3)2627 // same for the changed 'done' prop28 expect(baseState[1].done).toBe(false)29 expect(nextState[1].done).toBe(true)3031 // unchanged data is structurally shared32 expect(nextState[0]).toBe(baseState[0])33 // changed data not (dûh)34 expect(nextState[1]).not.toBe(baseState[1])35 })36})