base.js
This file
Path
__tests__/base.js
1,246 lines · 40.5 KiB · JavaScript
Last changed by
Verified listener doesn't break base implMichel Weststratebefore adoption6504581
History of this fileTake it
Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 1why, one step back1"use strict"Renamed `index.js` -> `immer.js`Michel Weststratebefore adoptionc4f5667
line 2why, one step back2import produce, {setAutoFreeze, setUseProxies} from "../src/immer"Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
line 3why, one step back3import deepFreeze from "deep-freeze"Reproduced #66Michel Weststratebefore adoptiond5de885
line 4why, one step back4import cloneDeep from "lodash.clonedeep"added some additional tests to verify solution correctness of #86Michel Weststratebefore adoption681b162
line 5why, one step back5import * as lodash from "lodash"More repo setupMichel Weststratebefore adoption1637393
line 6why, one step back6Making several improvements at onceMichel Weststratebefore adoption1116ccf
lines 7–8why, one step back7jest.setTimeout(1000)8Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0
lines 9–10why, one step back9runBaseTest("proxy (no freeze)", true, false)10runBaseTest("proxy (autofreeze)", true, true)Verified listener doesn't break base implMichel Weststratebefore adoption6504581
line 11why, one step back11runBaseTest("proxy (autofreeze)(patch listener)", true, true, true)Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0
lines 12–13why, one step back12runBaseTest("es5 (no freeze)", false, false)13runBaseTest("es5 (autofreeze)", false, true)Verified listener doesn't break base implMichel Weststratebefore adoption6504581
line 14why, one step back14runBaseTest("es5 (autofreeze)(patch listener)", false, true, true)Make debugging workMichel Weststratebefore adoptiond0ef4ed
line 15why, one step back15Verified listener doesn't break base implMichel Weststratebefore adoption6504581
line 16why, one step back16function runBaseTest(name, useProxies, freeze, useListener) {Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 17–19why, one step back17 describe(`base functionality - ${name}`, () => {18 let baseState19 let origBaseStateVerified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 20–21why, one step back20 // make sure logic doesn't break when listener is attached21 let listener = useListener ? function() {} : undefinedMake debugging workMichel Weststratebefore adoptiond0ef4ed
line 22why, one step back22Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 23why, one step back23 beforeEach(() => {Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0
lines 24–25why, one step back24 setAutoFreeze(freeze)25 setUseProxies(useProxies)Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 26–27why, one step back26 origBaseState = baseState = createBaseState()27 })Make debugging workMichel Weststratebefore adoptiond0ef4ed
line 28why, one step back28Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 29why, one step back29 it("should return the original without modifications", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
line 30why, one step back30 const nextState = produce(baseState, () => {}, listener)Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 31why, one step back31 expect(nextState).toBe(baseState)Wrote tests, fixed a bugMichel Weststratebefore adoption46e1d5d
lines 32–33why, one step back32 })33Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 34why, one step back34 it("should return the original without modifications when reading stuff", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 35–42why, one step back35 const nextState = produce(36 baseState,37 s => {38 expect(s.aProp).toBe("hi")39 expect(s.anObject.nested).toMatchObject({yummie: true})40 },41 listener42 )Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 43–44why, one step back43 expect(nextState).toBe(baseState)44 })Merge branch 'Gregjarvez-master'Michel Weststratebefore adoptiona151fed
line 45why, one step back45Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 46why, one step back46 it("should return a copy when modifying stuff", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 47–53why, one step back47 const nextState = produce(48 baseState,49 s => {50 s.aProp = "hello world"51 },52 listener53 )Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 54–58why, one step back54 expect(nextState).not.toBe(baseState)55 expect(baseState.aProp).toBe("hi")56 expect(nextState.aProp).toBe("hello world")57 // structural sharing?58 expect(nextState.nested).toBe(baseState.nested)Wrote tests, fixed a bugMichel Weststratebefore adoption46e1d5d
lines 59–60why, one step back59 })60Merge pull request #158 from stefanwille/base-test-uses-if-instead-of-itbenbraoubefore adoption0d04d62
line 61why, one step back61 it("should preserve type", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 62–73why, one step back62 const nextState = produce(63 baseState,64 s => {65 expect(Object.getPrototypeOf(s)).toBe(Object.prototype)66 expect(Array.isArray(s.anArray)).toBe(true)67 s.anArray.push(3)68 s.aProp = "hello world"69 expect(Object.getPrototypeOf(s)).toBe(Object.prototype)70 expect(Array.isArray(s.anArray)).toBe(true)71 },72 listener73 )Merge pull request #158 from stefanwille/base-test-uses-if-instead-of-itbenbraoubefore adoption0d04d62
lines 74–78why, one step back74 expect(Object.getPrototypeOf(nextState)).toBe(Object.prototype)75 expect(Array.isArray(nextState.anArray)).toBe(true)76 })7778 it("deep change bubbles up", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 79–85why, one step back79 const nextState = produce(80 baseState,81 s => {82 s.anObject.nested.yummie = false83 },84 listener85 )Merge pull request #158 from stefanwille/base-test-uses-if-instead-of-itbenbraoubefore adoption0d04d62
lines 86–91why, one step back86 expect(nextState).not.toBe(baseState)87 expect(nextState.anObject).not.toBe(baseState.anObject)88 expect(baseState.anObject.nested.yummie).toBe(true)89 expect(nextState.anObject.nested.yummie).toBe(false)90 expect(nextState.anArray).toBe(baseState.anArray)91 })Wrote tests, fixed a bugMichel Weststratebefore adoption46e1d5d
line 92why, one step back92Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 93why, one step back93 it("can add props", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 94–100why, one step back94 const nextState = produce(95 baseState,96 s => {97 s.anObject.cookie = {tasty: true}98 },99 listener100 )Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 101–104why, one step back101 expect(nextState).not.toBe(baseState)102 expect(nextState.anObject).not.toBe(baseState.anObject)103 expect(nextState.anObject.nested).toBe(baseState.anObject.nested)104 expect(nextState.anObject.cookie).toEqual({tasty: true})Wrote tests, fixed a bugMichel Weststratebefore adoption46e1d5d
lines 105–106why, one step back105 })106Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 107why, one step back107 it("can delete props", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 108–114why, one step back108 const nextState = produce(109 baseState,110 s => {111 delete s.anObject.nested112 },113 listener114 )Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 115–117why, one step back115 expect(nextState).not.toBe(baseState)116 expect(nextState.anObject).not.toBe(baseState.anObject)117 expect(nextState.anObject.nested).toBe(undefined)Wrote tests, fixed a bugMichel Weststratebefore adoption46e1d5d
lines 118–119why, one step back118 })119Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 120why, one step back120 it("ignores single non-modification", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 121–127why, one step back121 const nextState = produce(122 baseState,123 s => {124 s.aProp = "hi"125 },126 listener127 )Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 128why, one step back128 expect(nextState).toBe(baseState)Wrote tests, fixed a bugMichel Weststratebefore adoption46e1d5d
lines 129–130why, one step back129 })130Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 131why, one step back131 it("processes single modification", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 132–139why, one step back132 const nextState = produce(133 baseState,134 s => {135 s.aProp = "hello"136 s.aProp = "hi"137 },138 listener139 )Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 140–141why, one step back140 expect(nextState).not.toBe(baseState)141 expect(nextState).toEqual(baseState)Add support for arraysMichel Weststratebefore adoptiond3696cb
lines 142–143why, one step back142 })143Merge branch 'iruca3-fix/creating_array_proxy'Michel Weststratebefore adoption374ad85
lines 144–167why, one step back144 it("processes with for loop", () => {145 const base = [{id: 1, a: 1}, {id: 2, a: 1}]146 const findById = (collection, id) => {147 for (const item of collection) {148 if (item.id === id) return item149 }150 return null151 }152 const result = produce(base, draft => {153 const obj1 = findById(draft, 1)154 const obj2 = findById(draft, 2)155 obj1.a = 2156 obj2.a = 2157 })158 expect(result[0].a).toEqual(2)159 expect(result[1].a).toEqual(2)160 })161162 it("works with objects without proto", () => {163 const base = Object.create(null)164 base.x = 1165 base.y = Object.create(null)166 base.y.y = 2167 expect(base.__proto__).toBe(undefined)Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 168–176why, one step back168 const next = produce(169 base,170 draft => {171 draft.y.z = 3172 draft.y.y++173 draft.x++174 },175 listener176 )Merge branch 'iruca3-fix/creating_array_proxy'Michel Weststratebefore adoption374ad85
lines 177–183why, one step back177 expect(next).toEqual({178 x: 2,179 y: {y: 3, z: 3}180 })181 expect(next.__proto__).toBe(undefined)182 })183Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 184why, one step back184 it("should support reading arrays", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 185–191why, one step back185 const nextState = produce(186 baseState,187 s => {188 s.anArray.slice()189 },190 listener191 )Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 192–193why, one step back192 expect(nextState.anArray).toBe(baseState.anArray)193 expect(nextState).toBe(baseState)Add support for arraysMichel Weststratebefore adoptiond3696cb
lines 194–195why, one step back194 })195Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 196why, one step back196 it("should support changing arrays", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 197–203why, one step back197 const nextState = produce(198 baseState,199 s => {200 s.anArray[3] = true201 },202 listener203 )Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 204–206why, one step back204 expect(nextState).not.toBe(baseState)205 expect(nextState.anArray).not.toBe(baseState.anArray)206 expect(nextState.anArray[3]).toEqual(true)Add support for arraysMichel Weststratebefore adoptiond3696cb
lines 207–208why, one step back207 })208Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 209why, one step back209 it("should support changing arrays - 2", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 210–216why, one step back210 const nextState = produce(211 baseState,212 s => {213 s.anArray.splice(1, 1, "a", "b")214 },215 listener216 )Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 217–218why, one step back217 expect(nextState).not.toBe(baseState)218 expect(nextState.anArray).not.toBe(baseState.anArray)Add support for arraysMichel Weststratebefore adoptiond3696cb
line 219why, one step back219Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 220–226why, one step back220 expect(enumerableOnly(nextState.anArray)).toEqual([221 3,222 "a",223 "b",224 {c: 3},225 1226 ])Add support for arraysMichel Weststratebefore adoptiond3696cb
lines 227–228why, one step back227 })228Merge pull request #38 from mweststrate/feature/performanceMichel Weststratebefore adoption670fcff
line 229why, one step back229 it("can delete array items", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 230–236why, one step back230 const nextState = produce(231 baseState,232 s => {233 s.anArray.length = 3234 },235 listener236 )Merge pull request #38 from mweststrate/feature/performanceMichel Weststratebefore adoption670fcff
lines 237–242why, one step back237 expect(nextState).not.toBe(baseState)238 expect(nextState.anObject).toBe(baseState.anObject)239 expect(nextState.anArray).not.toBe(baseState.anArray)240 expect(nextState.anArray).toEqual([3, 2, {c: 3}])241 })242Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 243why, one step back243 it("should support sorting arrays", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 244–252why, one step back244 const nextState = produce(245 baseState,246 s => {247 s.anArray[2].c = 4248 s.anArray.sort()249 s.anArray[3].c = 5250 },251 listener252 )Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 253–254why, one step back253 expect(nextState).not.toBe(baseState)254 expect(nextState.anArray).not.toBe(baseState.anArray)Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
line 255why, one step back255 expect(enumerableOnly(nextState.anArray)).toEqual([1, 2, 3, {c: 5}])Code cleanupMichel Weststratebefore adoption2b2d0cb
lines 256–257why, one step back256 })257Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
line 258why, one step back258 it("should expose property descriptors", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 259–276why, one step back259 const nextState = produce(260 [],261 s => {262 expect(Object.getOwnPropertyDescriptor(s, 0)).toBe(263 undefined264 )265 s.unshift("x")266 expect(Object.getOwnPropertyDescriptor(s, 0)).toEqual({267 configurable: true,268 enumerable: true,269 value: "x",270 writable: true271 })272 expect(s.length).toBe(1)273 expect(s[0] === "x").toBe(true)274 },275 listener276 )Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 277–286why, one step back277 expect(nextState).toEqual(["x"])278 expect(Object.getOwnPropertyDescriptor(nextState, 0)).toEqual({279 configurable: !freeze,280 enumerable: true,281 value: "x",282 writable: !freeze283 })284 })285286 it("should support sorting arrays - 2", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 287–297why, one step back287 const nextState = produce(288 baseState,289 s => {290 s.anArray.unshift("x")291 s.anArray[3].c = 4292 s.anArray.sort()293 s.anArray[3].c = 5294 s.anArray.unshift("y")295 },296 listener297 )Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 298–309why, one step back298 expect(nextState).not.toBe(baseState)299 expect(nextState.anArray).not.toBe(baseState.anArray)300 expect(enumerableOnly(nextState.anArray)).toEqual([301 "y",302 1,303 2,304 3,305 {c: 5},306 "x"307 ])308 })309Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 310why, one step back310 it("should updating inside arrays", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 311–317why, one step back311 const nextState = produce(312 baseState,313 s => {314 s.anArray[2].test = true315 },316 listener317 )Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 318–320why, one step back318 expect(nextState).not.toBe(baseState)319 expect(nextState.anArray).not.toBe(baseState.anArray)320 expect(nextState.anArray).toEqual([3, 2, {c: 3, test: true}, 1])Fixed bug, wrote readmeMichel Weststratebefore adoption1b8a694
lines 321–322why, one step back321 })322Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 323why, one step back323 it("reusing object should work", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 324–332why, one step back324 const nextState = produce(325 baseState,326 s => {327 const obj = s.anObject328 delete s.anObject329 s.messy = obj330 },331 listener332 )Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 333–334why, one step back333 expect(nextState).not.toBe(baseState)334 expect(nextState.anArray).toBe(baseState.anArray)Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
line 335why, one step back335 expect(enumerableOnly(nextState)).toEqual({Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 336–345why, one step back336 anArray: [3, 2, {c: 3}, 1],337 aProp: "hi",338 messy: {339 nested: {340 yummie: true341 },342 coffee: false343 }344 })345 expect(nextState.messy.nested).toBe(baseState.anObject.nested)Fixed bug, wrote readmeMichel Weststratebefore adoption1b8a694
lines 346–347why, one step back346 })347Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 348why, one step back348 it("refs should be transparent", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 349–359why, one step back349 const nextState = produce(350 baseState,351 s => {352 const obj = s.anObject353 s.aProp = "hello"354 delete s.anObject355 obj.coffee = true356 s.messy = obj357 },358 listener359 )Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 360–361why, one step back360 expect(nextState).not.toBe(baseState)361 expect(nextState.anArray).toBe(baseState.anArray)Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
line 362why, one step back362 expect(enumerableOnly(nextState)).toEqual({Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 363–372why, one step back363 anArray: [3, 2, {c: 3}, 1],364 aProp: "hello",365 messy: {366 nested: {367 yummie: true368 },369 coffee: true370 }371 })372 expect(nextState.messy.nested).toBe(baseState.anObject.nested)Merge pull request #13 from benbraou/issue12Michel Weststratebefore adoption8eab91e
lines 373–374why, one step back373 })374Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 375why, one step back375 it("should allow setting to undefined a defined draft property", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 376–382why, one step back376 const nextState = produce(377 baseState,378 s => {379 s.aProp = undefined380 },381 listener382 )Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 383–385why, one step back383 expect(nextState).not.toBe(baseState)384 expect(baseState.aProp).toBe("hi")385 expect(nextState.aProp).toBe(undefined)Merge pull request #14 from benbraou/issue10Michel Weststratebefore adoptione775cca
lines 386–387why, one step back386 })387Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 388why, one step back388 // ES implementation does't protect against all outside modifications, just some..Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0
line 389why, one step back389 if (useProxies) {Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 390–391why, one step back390 it("should revoke the proxy of the baseState after immer function is executed", () => {391 let proxyVerified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 392–399why, one step back392 const nextState = produce(393 baseState,394 s => {395 proxy = s396 s.aProp = "hello"397 },398 listener399 )Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 400–402why, one step back400 expect(nextState).not.toBe(baseState)401 expect(baseState.aProp).toBe("hi")402 expect(nextState.aProp).toBe("hello")Merge pull request #14 from benbraou/issue10Michel Weststratebefore adoptione775cca
line 403why, one step back403Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 404–409why, one step back404 expect(() => {405 proxy.aProp = "Hallo"406 }).toThrowError(/revoked/)407 expect(() => {408 const aProp = proxy.aProp409 }).toThrowError(/revoked/)Merge pull request #15 from mweststrate/feature/freezeMichel Weststratebefore adoption0d24494
line 410why, one step back410Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 411–418why, one step back411 expect(nextState).not.toBe(baseState)412 expect(baseState.aProp).toBe("hi")413 expect(nextState.aProp).toBe("hello")414 })415 }416417 it("should revoke the proxy of the baseState after immer function is executed - 2", () => {418 let proxyVerified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 419–425why, one step back419 const nextState = produce(420 baseState,421 s => {422 proxy = s.anObject423 },424 listener425 )Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 426–433why, one step back426 expect(nextState).toBe(baseState)427 expect(() => {428 // In ES5 implemenation only protects existing props, but alas..429 proxy.coffee = "Hallo"430 }).toThrowError(/revoked/)431 expect(() => {432 const test = proxy.coffee433 }).toThrowError(/revoked/)Updated changelogMichel Weststratebefore adoption8f44348
lines 434–435why, one step back434 })435Added a testcaseMichel Weststratebefore adoption1e468fd
line 436why, one step back436 it("should reflect all changes made in the draft immediately", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 437–454why, one step back437 produce(438 baseState,439 draft => {440 draft.anArray[0] = 5441 draft.anArray.unshift("test")442 // sliced here; jest will also compare non-enumerable keys, which would include the immer Symbols443 expect(draft.anArray.slice()).toMatchObject([444 "test",445 5,446 2,447 {c: 3},448 1449 ])450 draft.stuffz = "coffee"451 expect(draft.stuffz).toBe("coffee")452 },453 listener454 )Added a testcaseMichel Weststratebefore adoption1e468fd
line 455why, one step back455 })Fixed configurability of array.length on proxies. Fixes #50Michel Weststratebefore adoption1c7df26
lines 456–457why, one step back456457 it("should be able to get property descriptors from objects", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 458–467why, one step back458 produce(459 {a: 1},460 draft => {461 expect("a" in draft).toBe(true)462 expect("b" in draft).toBe(false)463 expect(464 Reflect.ownKeys(draft).filter(465 x => typeof x === "string"466 )467 ).toEqual(["a"])Fixed configurability of array.length on proxies. Fixes #50Michel Weststratebefore adoption1c7df26
line 468why, one step back468Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 469–501why, one step back469 expect(470 Object.getOwnPropertyDescriptor(draft, "a")471 ).toMatchObject({472 configurable: true,473 enumerable: true474 })475 draft.a = 2476 expect(477 Object.getOwnPropertyDescriptor(draft, "a")478 ).toMatchObject({479 configurable: true,480 enumerable: true481 })482 expect(483 Object.getOwnPropertyDescriptor(draft, "b")484 ).toBeUndefined()485 draft.b = 2486 expect(487 Object.getOwnPropertyDescriptor(draft, "b")488 ).toMatchObject({489 configurable: true,490 enumerable: true491 })492 expect("a" in draft).toBe(true)493 expect("b" in draft).toBe(true)494 expect(495 Reflect.ownKeys(draft).filter(496 x => typeof x === "string"497 )498 ).toEqual(["a", "b"])499 },500 listener501 )Fixed configurability of array.length on proxies. Fixes #50Michel Weststratebefore adoption1c7df26
lines 502–504why, one step back502 })503504 it("should be able to get property descriptors from arrays", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 505–517why, one step back505 produce(506 [1],507 draft => {508 expect(0 in draft).toBe(true)509 expect(1 in draft).toBe(false)510 expect("0" in draft).toBe(true)511 expect("1" in draft).toBe(false)512 expect(length in draft).toBe(true)513 expect(514 Reflect.ownKeys(draft).filter(515 x => typeof x === "string"516 )517 ).toEqual(["0", "length"])Fixed configurability of array.length on proxies. Fixes #50Michel Weststratebefore adoption1c7df26
line 518why, one step back518Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 519–528why, one step back519 expect(520 Object.getOwnPropertyDescriptor(draft, "length")521 ).toMatchObject({522 configurable: false,523 enumerable: false524 })525 draft[0] = 2526 expect(527 Object.getOwnPropertyDescriptor(draft, 0)528 ).toMatchObject({Fixed configurability of array.length on proxies. Fixes #50Michel Weststratebefore adoption1c7df26
lines 529–530why, one step back529 configurable: true,530 enumerable: trueVerified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 531–534why, one step back531 })532 expect(533 Object.getOwnPropertyDescriptor(draft, 0)534 ).toMatchObject({Fixed configurability of array.length on proxies. Fixes #50Michel Weststratebefore adoption1c7df26
lines 535–536why, one step back535 configurable: true,536 enumerable: trueVerified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 537–544why, one step back537 })538 expect(539 Object.getOwnPropertyDescriptor(draft, 1)540 ).toBeUndefined()541 draft[1] = 2542 expect(543 Object.getOwnPropertyDescriptor(draft, 1)544 ).toMatchObject({Fixed configurability of array.length on proxies. Fixes #50Michel Weststratebefore adoption1c7df26
lines 545–546why, one step back545 configurable: true,546 enumerable: trueVerified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 547–555why, one step back547 })548 expect(549 Reflect.ownKeys(draft).filter(550 x => typeof x === "string"551 )552 ).toEqual(["0", "1", "length"])553 },554 listener555 )Fixed configurability of array.length on proxies. Fixes #50Michel Weststratebefore adoption1c7df26
lines 556–557why, one step back556 })557Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0
line 558why, one step back558 if (useProxies === true) {Fixed configurability of array.length on proxies. Fixes #50Michel Weststratebefore adoption1c7df26
lines 559–560why, one step back559 it("should not be possible to set property descriptors", () => {560 expect(() => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 561–571why, one step back561 produce(562 {},563 draft => {564 Object.defineProperty(draft, "xx", {565 enumerable: true,566 writeable: true,567 value: 2568 })569 },570 listener571 )Fixed configurability of array.length on proxies. Fixes #50Michel Weststratebefore adoption1c7df26
lines 572–573why, one step back572 }).toThrowError(/not support/)573 })Merge pull request #68 from mweststrate/feature/reuseMichel Weststratebefore adoption20394c0
line 574why, one step back574 }initial solutionMichel Weststratebefore adoptiond618d28
line 575why, one step back575Faster, simpler implementationMichel Weststratebefore adoptionc420f0d
lines 576–577why, one step back576 it("should not throw error, see #53 - 1", () => {577 const base = {arr: [{count: 1}, {count: 2}, {count: 3}]}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 578–584why, one step back578 const result = produce(579 base,580 draft => {581 draft.arr = draft.arr.filter(item => item.count > 2)582 },583 listener584 )initial solutionMichel Weststratebefore adoptiond618d28
line 585why, one step back585 expect(result.arr[0].count).toEqual(3)Faster, simpler implementationMichel Weststratebefore adoptionc420f0d
lines 586–593why, one step back586 expect(result).toEqual({587 arr: [{count: 3}]588 })589 expect(result.arr[0]).toBe(base.arr[2])590 })591592 it("should not throw error, see #53 - 2", () => {593 const base = {arr: [{count: 1}, {count: 2}, {count: 3}]}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 594–600why, one step back594 const result = produce(595 base,596 draft => {597 draft.newArr = draft.arr.filter(item => item.count > 2)598 },599 listener600 )Faster, simpler implementationMichel Weststratebefore adoptionc420f0d
lines 601–620why, one step back601 expect(result.newArr[0].count).toEqual(3)602 expect(result.arr).toBe(base.arr)603 expect(result).toEqual({604 arr: [605 {606 count: 1607 },608 {609 count: 2610 },611 {612 count: 3613 }614 ],615 newArr: [616 {617 count: 3618 }619 ]620 })Making several improvements at onceMichel Weststratebefore adoption1116ccf
lines 621–622why, one step back621 expect(result.newArr[0]).toBe(base.arr[2])622 expect(result.arr[2]).toBe(base.arr[2])Faster, simpler implementationMichel Weststratebefore adoptionc420f0d
lines 623–626why, one step back623 })624625 it("should not throw error, see #53 - 3", () => {626 const base = {arr: [{count: 1}, {count: 2}, {count: 3}]}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 627–634why, one step back627 const result = produce(628 base,629 draft => {630 draft.newArr = draft.arr.filter(item => item.count > 2)631 delete draft.arr632 },633 listener634 )Faster, simpler implementationMichel Weststratebefore adoptionc420f0d
lines 635–639why, one step back635 expect(result.newArr[0].count).toEqual(3)636 expect(result).toEqual({637 newArr: [{count: 3}]638 })639 expect(result.newArr[0]).toBe(base.arr[2])initial solutionMichel Weststratebefore adoptiond618d28
line 640why, one step back640 })Added a testcaseMichel Weststratebefore adoption1e468fd
line 641why, one step back641Making several improvements at onceMichel Weststratebefore adoption1116ccf
lines 642–643why, one step back642 it("should not throw error, see #53 - 4", () => {643 const base = {bear: {age: 10}}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 644–651why, one step back644 const result = produce(645 base,646 draft => {647 draft.bear.legs = 4648 draft.room = {elephant: {kiddo: draft.bear}}649 },650 listener651 )Making several improvements at onceMichel Weststratebefore adoption1116ccf
lines 652–666why, one step back652 expect(result).toEqual({653 bear: {age: 10, legs: 4},654 room: {elephant: {kiddo: {age: 10, legs: 4}}}655 })656657 const result2 = produce(result, draft => {658 draft.bear.age = 11659 draft.room.elephant.kiddo.legs = 5660 })661 expect(result2).toEqual({662 bear: {age: 11, legs: 4},663 room: {elephant: {kiddo: {age: 10, legs: 5}}}664 })665 })666Merge branch 'iruca3-fix/finalize'Michel Weststratebefore adoption425f092
lines 667–715why, one step back667 it("should not throw error #78", () => {668 const base = {669 arr: [670 {671 id: "100",672 arr: [{id: "1", no: 1}, {id: "2", no: 2}]673 },674 {id: "3", no: 3}675 ]676 }677 const result = produce(base, draft => {678 const base = draft.arr[0]679 draft.arr = draft.arr.slice(0, 1)680 const newArr = {681 id: "101",682 arr: [base, {id: "3"}]683 }684 draft.arr.splice(0, 1, newArr)685 draft.arr[0].arr[1].no = 3686 })687 expect(result).toEqual({688 arr: [689 {690 id: "101",691 arr: [692 {693 id: "100",694 arr: [{id: "1", no: 1}, {id: "2", no: 2}]695 },696 {id: "3", no: 3}697 ]698 }699 ]700 })701 })702703 it("should not throw error #78 - 2", () => {704 const base = {705 arr: [{count: 1}, {count: 2}]706 }707 const result = produce(base, draft => {708 draft.arr = [draft.arr[1]]709 draft.arr[0].count = 1710 })711 expect(result).toEqual({712 arr: [{count: 1}]713 })714 })715Merge pull request #81 from iruca3/fix/treating_constructor_on_proxyMichel Weststratebefore adoptionad5a86a
lines 716–728why, one step back716 it("should handle constructor correctly", () => {717 const base = {718 arr: new Array(),719 obj: new Object()720 }721 const result = produce(base, draft => {722 draft.arrConstructed = draft.arr.constructor(1)723 draft.objConstructed = draft.obj.constructor(1)724 })725 expect(result.arrConstructed).toEqual(new Array().constructor(1))726 expect(result.objConstructed).toEqual(new Object().constructor(1))727 })728Making several improvements at onceMichel Weststratebefore adoption1116ccf
lines 729–772why, one step back729 it("should handle dates correctly", () => {730 const data = {date: new Date()}731 const next = produce(data, draft => {732 draft.x = true733 })734 expect(next).toEqual({x: true, date: data.date})735 expect(next.date).toBe(data.date)736 const next2 = produce(next, draft => {737 draft.date.setYear(2015)738 })739 // This still holds; because produce won't proxy Date objects740 // and the original is actually modified!741 expect(next2).toEqual({x: true, date: data.date})742 expect(next2.date).toBe(next.date)743 expect(next2.date).toBe(data.date)744 expect(next2).toBe(next)745 })746747 it("should handle equality correctly - 1", () => {748 const base = {749 y: 3 / 0,750 z: NaN751 }752 const next = produce(base, draft => {753 draft.y = 4 / 0754 draft.z = NaN755 })756 expect(next).toEqual(base)757 expect(next).toBe(base)758 })759760 it("should handle equality correctly - 2", () => {761 const base = {762 x: -0763 }764 const next = produce(base, draft => {765 draft.x = +1766 })767 expect(next).not.toEqual(base)768 expect(next).not.toBe(base)769 })770771 it("should handle nested immer calls correctly - 1", () => {772 const bear = {paw: {honey: true}}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 773–783why, one step back773 const next = produce(774 bear,775 draft => {776 const paw2 = produce(bear.paw, draft => {777 draft.honey = false778 })779 expect(paw2.honey).toBe(false)780 expect(draft.paw.honey).toBe(true) // effects should not be visible outside781 },782 listener783 )Making several improvements at onceMichel Weststratebefore adoption1116ccf
lines 784–789why, one step back784 expect(next.paw.honey).toBe(true)785 expect(next).toBe(bear)786 })787788 it("should handle nested immer calls correctly - 2", () => {789 const bear = {paw: {honey: true}}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 790–802why, one step back790 const next = produce(791 bear,792 draft => {793 const paw2 = produce(bear.paw, draft => {794 draft.honey = false795 })796 expect(paw2.honey).toBe(false)797 expect(draft.paw.honey).toBe(true)798 draft.paw = paw2799 expect(draft.paw.honey).toBe(false)800 },801 listener802 )Making several improvements at onceMichel Weststratebefore adoption1116ccf
lines 803–804why, one step back803 expect(next.paw.honey).toBe(false)804 expect(next).not.toBe(bear)Reproduced #66Michel Weststratebefore adoptiond5de885
lines 805–810why, one step back805 })806807 it("should not try to change immutable data, see #66", () => {808 const user = require("./test-data")809810 const base = {}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 811–817why, one step back811 const next = produce(812 base,813 draft => {814 draft.user = user815 },816 listener817 )Reproduced #66Michel Weststratebefore adoptiond5de885
lines 818–826why, one step back818 expect(next.user).toBe(user)819 expect(next).not.toBe(base)820 expect(next.user).toEqual(user)821 })822823 it("should not try to change immutable data, see #66 - 2", () => {824 const user = deepFreeze(cloneDeep(require("./test-data")))825826 const base = {}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 827–833why, one step back827 const next = produce(828 base,829 draft => {830 draft.user = user831 },832 listener833 )Reproduced #66Michel Weststratebefore adoptiond5de885
lines 834–836why, one step back834 expect(next.user).toBe(user)835 expect(next).not.toBe(base)836 expect(next.user).toEqual(user)Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
lines 837–841why, one step back837 })838839 if (freeze)840 it("should freeze new data well", () => {841 const base = {}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 842–848why, one step back842 const next = produce(843 base,844 draft => {845 draft.x = {y: [{z: true}]}846 },847 listener848 )Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
lines 849–856why, one step back849 expect(Object.isFrozen(next)).toBe(true)850 expect(Object.isFrozen(next.x)).toBe(true)851 expect(Object.isFrozen(next.x.y)).toBe(true)852 expect(Object.isFrozen(next.x.y[0].z)).toBe(true)853 })854855 it("should structurally share identical objects in the tree", () => {856 const base = {bear: {legs: 4}, eagle: {legs: 3}}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 857–868why, one step back857 const next = produce(858 base,859 draft => {860 const animal = draft.bear861 animal.legs = animal.legs + 1862 draft.bear = animal863 draft.eagle = animal864 draft.cow = animal865 draft.kiddo = animal866 },867 listener868 )Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
lines 869–880why, one step back869 expect(next).toEqual({870 bear: {legs: 5},871 eagle: {legs: 5},872 cow: {legs: 5},873 kiddo: {legs: 5}874 })875 expect(next.bear).toBe(next.cow)876 expect(next.kiddo).toBe(next.cow)877 })878879 if (useProxies)880 it("should not allow changing prototype", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 881–889why, one step back881 produce(882 {},883 draft => {884 expect(() =>885 Object.setPrototypeOf(draft, Array)886 ).toThrow(/does not support `setPrototype/)887 },888 listener889 )Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
lines 890–891why, one step back890 })891Immer now changes the context (`this`) of producer functions by default to the draft stateMichel Weststratebefore adoption3a9d6d1
line 892why, one step back892 it("'in' should work", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 893–897why, one step back893 produce(894 createBaseState(),895 draft => {896 expect("anArray" in draft).toBe(true)897 expect(Reflect.has(draft, "anArray")).toBe(true)Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 898why, one step back898Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 899–900why, one step back899 expect("bla" in draft).toBe(false)900 expect(Reflect.has(draft, "bla")).toBe(false)Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 901why, one step back901Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 902–905why, one step back902 expect(0 in draft.anArray).toBe(true)903 expect("0" in draft.anArray).toBe(true)904 expect(Reflect.has(draft.anArray, 0)).toBe(true)905 expect(Reflect.has(draft.anArray, "0")).toBe(true)Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 906why, one step back906Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 907–913why, one step back907 expect(17 in draft.anArray).toBe(false)908 expect("17" in draft.anArray).toBe(false)909 expect(Reflect.has(draft.anArray, 17)).toBe(false)910 expect(Reflect.has(draft.anArray, "17")).toBe(false)911 },912 listener913 )Immer now changes the context (`this`) of producer functions by default to the draft stateMichel Weststratebefore adoption3a9d6d1
lines 914–917why, one step back914 })915916 it("'this' should work - 1", () => {917 const base = {x: 3}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 918–924why, one step back918 const next1 = produce(919 base,920 function() {921 this.x = 4922 },923 listener924 )Immer now changes the context (`this`) of producer functions by default to the draft stateMichel Weststratebefore adoption3a9d6d1
lines 925–936why, one step back925 expect(next1).not.toBe(base)926 expect(next1.x).toBe(4)927 })928929 it("'this' should work - 1", () => {930 const base = {x: 3}931 const incrementor = produce(function() {932 this.x = 4933 })934 const next1 = incrementor(base)935 expect(next1).not.toBe(base)936 expect(next1.x).toBe(4)Making several improvements at onceMichel Weststratebefore adoption1116ccf
lines 937–938why, one step back937 })938added test for #89Michel Weststratebefore adoptionf68a31a
lines 939–947why, one step back939 it("issue #89", () => {940 const state = {941 users: {942 existingID: {943 loading: false,944 value: "val"945 }946 }947 }Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 948–957why, one step back948 const nextState = produce(949 state,950 draft => {951 draft.users.existingID = {952 ...draft.users.existingID,953 loading: true954 }955 },956 listener957 )added test for #89Michel Weststratebefore adoptionf68a31a
lines 958–965why, one step back958 expect(nextState).toEqual({959 users: {960 existingID: {961 loading: true,962 value: "val"963 }964 }965 })added some additional tests to verify solution correctness of #86Michel Weststratebefore adoption681b162
lines 966–969why, one step back966 })967968 it("processes with lodash.set", () => {969 const base = [{id: 1, a: 1}]Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 970–976why, one step back970 const result = produce(971 base,972 draft => {973 lodash.set(draft, "[0].a", 2)974 },975 listener976 )added some additional tests to verify solution correctness of #86Michel Weststratebefore adoption681b162
lines 977–982why, one step back977 expect(base[0].a).toEqual(1)978 expect(result[0].a).toEqual(2)979 })980981 it("processes with lodash.find", () => {982 const base = [{id: 1, a: 1}]Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 983–990why, one step back983 const result = produce(984 base,985 draft => {986 const obj1 = lodash.find(draft, {id: 1})987 lodash.set(obj1, "a", 2)988 },989 listener990 )added some additional tests to verify solution correctness of #86Michel Weststratebefore adoption681b162
lines 991–992why, one step back991 expect(base[0].a).toEqual(1)992 expect(result[0].a).toEqual(2)Implemented and document #108: allow returning values from producersMichel Weststratebefore adoptionc589ddd
lines 993–996why, one step back993 })994995 it("can produce from no state", () => {996 expect(Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 997–1004why, one step back997 produce(998 3,999 draft => {1000 expect(draft).toBe(3)1001 return 51002 },1003 listener1004 )Implemented and document #108: allow returning values from producersMichel Weststratebefore adoptionc589ddd
lines 1005–1009why, one step back1005 ).toBe(5)1006 })10071008 it("can return something new ", () => {1009 const base = {x: 3}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 1010–1016why, one step back1010 const res = produce(1011 base,1012 draft => {1013 return {x: draft.x + 1}1014 },1015 listener1016 )Implemented and document #108: allow returning values from producersMichel Weststratebefore adoptionc589ddd
lines 1017–1022why, one step back1017 expect(res).not.toBe(base)1018 expect(res).toEqual({x: 4})1019 })10201021 it("can return the draft new ", () => {1022 const base = {x: 3}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 1023–1030why, one step back1023 const res = produce(1024 base,1025 draft => {1026 draft.x = 41027 return draft1028 },1029 listener1030 )Implemented and document #108: allow returning values from producersMichel Weststratebefore adoptionc589ddd
lines 1031–1037why, one step back1031 expect(res).not.toBe(base)1032 expect(res).toEqual({x: 4})1033 })10341035 it("should throw if modifying the draft and returning something new", () => {1036 const base = {x: 3}1037 expect(() => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 1038–1045why, one step back1038 produce(1039 base,1040 draft => {1041 draft.x = 41042 return {x: 5}1043 },1044 listener1045 )Implemented and document #108: allow returning values from producersMichel Weststratebefore adoptionc589ddd
line 1046why, one step back1046 }).toThrow(/An immer producer returned a new value/)added test for #89Michel Weststratebefore adoptionf68a31a
lines 1047–1048why, one step back1047 })1048Fixed #116, failed to detect array changes when made shorter, then longerMichel Weststratebefore adoption76d33df
line 1049why, one step back1049 it("should fix #116", () => {Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 1050–1057why, one step back1050 const nextState = produce(1051 [1, 2, 3],1052 s => {1053 s.pop()1054 s.push(100)1055 },1056 listener1057 )Fixed #116, failed to detect array changes when made shorter, then longerMichel Weststratebefore adoption76d33df
lines 1058–1060why, one step back1058 expect(nextState).toEqual([1, 2, 100])1059 })1060Fixed #117 returned proxies not being finalized when only a subset was returnedMichel Weststratebefore adoption8e61145
lines 1061–1062why, one step back1061 it("should fix #117", () => {1062 const reducer = (state, action) =>Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 1063–1074why, one step back1063 produce(1064 state,1065 draft => {1066 switch (action.type) {1067 case "SET_STARTING_DOTS":1068 return draft.availableStartingDots.map(a => a)1069 default:1070 break1071 }1072 },1073 listener1074 )Fixed #117 returned proxies not being finalized when only a subset was returnedMichel Weststratebefore adoption8e61145
lines 1075–1089why, one step back1075 const base = {1076 availableStartingDots: [1077 {dots: 4, count: 1},1078 {dots: 3, count: 2},1079 {dots: 2, count: 3},1080 {dots: 1, count: 4}1081 ]1082 }1083 const next = reducer(base, {type: "SET_STARTING_DOTS"})1084 expect(next).toEqual(base.availableStartingDots)1085 expect(next).not.toBe(base.availableStartingDots)1086 })10871088 it("should fix #117 - 2", () => {1089 const reducer = (state, action) =>Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 1090–1105why, one step back1090 produce(1091 state,1092 draft => {1093 switch (action.type) {1094 case "SET_STARTING_DOTS":1095 return {1096 dots: draft.availableStartingDots.map(1097 a => a1098 )1099 }1100 default:1101 break1102 }1103 },1104 listener1105 )Fixed #117 returned proxies not being finalized when only a subset was returnedMichel Weststratebefore adoption8e61145
lines 1106–1117why, one step back1106 const base = {1107 availableStartingDots: [1108 {dots: 4, count: 1},1109 {dots: 3, count: 2},1110 {dots: 2, count: 3},1111 {dots: 1, count: 4}1112 ]1113 }1114 const next = reducer(base, {type: "SET_STARTING_DOTS"})1115 expect(next).toEqual({dots: base.availableStartingDots})1116 })1117Merge pull request #157 from stefanwille/fix-148-default-returned-valueMichel Weststratebefore adoptiond87d637
lines 1118–1119why, one step back1118 it("should return an unmodified primitive baseState (#148)", () => {1119 const baseState = "some string"Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 1120–1126why, one step back1120 const nextState = produce(1121 baseState,1122 () => {1123 /* no modification */1124 },1125 listener1126 )Merge pull request #157 from stefanwille/fix-148-default-returned-valueMichel Weststratebefore adoptiond87d637
lines 1127–1131why, one step back1127 expect(nextState).toBe(baseState)1128 })11291130 it("should return an unmodified null baseState (#148)", () => {1131 const baseState = nullVerified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 1132–1138why, one step back1132 const nextState = produce(1133 baseState,1134 () => {1135 /* no modification */1136 },1137 listener1138 )Merge pull request #157 from stefanwille/fix-148-default-returned-valueMichel Weststratebefore adoptiond87d637
lines 1139–1141why, one step back1139 expect(nextState).toBe(baseState)1140 })1141Patches now also succeed for ES5. Patches generated are more optimalMichel Weststratebefore adoptionfd9ed2d
lines 1142–1143why, one step back1142 it("should not detect noop assignments - 0", () => {1143 const baseState = {x: {y: 3}}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 1144–1151why, one step back1144 const nextState = produce(1145 baseState,1146 d => {1147 const a = d.x1148 d.x = a1149 },1150 listener1151 )Patches now also succeed for ES5. Patches generated are more optimalMichel Weststratebefore adoptionfd9ed2d
lines 1152–1156why, one step back1152 expect(nextState).toBe(baseState)1153 })11541155 it("should not detect noop assignments - 1", () => {1156 const baseState = {x: {y: 3}}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 1157–1165why, one step back1157 const nextState = produce(1158 baseState,1159 d => {1160 const a = d.x1161 d.x = 41162 d.x = a1163 },1164 listener1165 )Patches now also succeed for ES5. Patches generated are more optimalMichel Weststratebefore adoptionfd9ed2d
lines 1166–1173why, one step back1166 // Ideally, this should actually be the same instances1167 // but this would be pretty expensive to detect,1168 // so we don't atm1169 expect(nextState).not.toBe(baseState)1170 })11711172 it("should not detect noop assignments - 2", () => {1173 const baseState = {x: {y: 3}}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 1174–1183why, one step back1174 const nextState = produce(1175 baseState,1176 d => {1177 const a = d.x1178 const stuff = a.y + 31179 d.x = 41180 d.x = a1181 },1182 listener1183 )Patches now also succeed for ES5. Patches generated are more optimalMichel Weststratebefore adoptionfd9ed2d
lines 1184–1189why, one step back1184 // Ideally, this should actually be the same instances1185 // but this would be pretty expensive to detect,1186 // so we don't atm1187 expect(nextState).not.toBe(baseState)1188 })1189Fixed & added testsMichel Weststratebefore adoptionaf95dc8
lines 1190–1191why, one step back1190 it("should not detect noop assignments - 3", () => {1191 const baseState = {x: 3}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 1192–1198why, one step back1192 const nextState = produce(1193 baseState,1194 d => {1195 d.x = 31196 },1197 listener1198 )Fixed & added testsMichel Weststratebefore adoptionaf95dc8
lines 1199–1203why, one step back1199 expect(nextState).toBe(baseState)1200 })12011202 it("should not detect noop assignments - 4", () => {1203 const baseState = {x: 3}Verified listener doesn't break base implMichel Weststratebefore adoption6504581
lines 1204–1211why, one step back1204 const nextState = produce(1205 baseState,1206 d => {1207 d.x = 41208 d.x = 31209 },1210 listener1211 )Fixed & added testsMichel Weststratebefore adoptionaf95dc8
lines 1212–1217why, one step back1212 // Ideally, this should actually be the same instances1213 // but this would be pretty expensive to detect,1214 // so we don't atm1215 expect(nextState).not.toBe(baseState)1216 })1217added `np` for easier releasingMichel Weststratebefore adoption23bfaa2
lines 1218–1221why, one step back1218 it("immer should have no dependencies", () => {1219 expect(require("../package.json").dependencies).toEqual(undefined)1220 })1221Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 1222–1225why, one step back1222 afterEach(() => {1223 expect(baseState).toBe(origBaseState)1224 expect(baseState).toEqual(createBaseState())1225 })Make debugging workMichel Weststratebefore adoptiond0ef4ed
line 1226why, one step back1226Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 1227why, one step back1227 function createBaseState() {Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
line 1228why, one step back1228 const data = {Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
lines 1229–1236why, one step back1229 anArray: [3, 2, {c: 3}, 1],1230 aProp: "hi",1231 anObject: {1232 nested: {1233 yummie: true1234 },1235 coffee: false1236 }No trailing commas, might break babel, fixes #21Michel Weststratebefore adoption2a1da31
line 1237why, one step back1237 }Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
line 1238why, one step back1238 return freeze ? deepFreeze(data) : dataMake debugging workMichel Weststratebefore adoptiond0ef4ed
line 1239why, one step back1239 }Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 1240why, one step back1240 })Merge pull request #33 from mweststrate/fix/32Michel Weststratebefore adoptionfae0957
lines 1241–1245why, one step back1241}12421243function enumerableOnly(x) {1244 // this can be done better...1245 return JSON.parse(JSON.stringify(x))Merge pull request #22 from mweststrate/feature/es5Michel Weststratebefore adoption4165abb
line 1246why, one step back1246}