base.js
This file
Path
__tests__/base.js
885 lines · 30.4 KiB · JavaScript
Last changed by
Fixed #116, failed to detect array changes when made shorter, then longerMichel Weststratebefore adoption76d33df
History of this fileTake it
1"use strict"2import produce, {setAutoFreeze, setUseProxies} from "../src/immer"3import deepFreeze from "deep-freeze"4import cloneDeep from "lodash.clonedeep"5import * as lodash from "lodash"67jest.setTimeout(1000)89runBaseTest("proxy (no freeze)", true, false)10runBaseTest("proxy (autofreeze)", true, true)11runBaseTest("es5 (no freeze)", false, false)12runBaseTest("es5 (autofreeze)", false, true)1314function runBaseTest(name, useProxies, freeze) {15 describe(`base functionality - ${name}`, () => {16 let baseState17 let origBaseState1819 beforeEach(() => {20 setAutoFreeze(freeze)21 setUseProxies(useProxies)22 origBaseState = baseState = createBaseState()23 })2425 it("should return the original without modifications", () => {26 const nextState = produce(baseState, () => {})27 expect(nextState).toBe(baseState)28 })2930 it("should return the original without modifications when reading stuff", () => {31 const nextState = produce(baseState, s => {32 expect(s.aProp).toBe("hi")33 expect(s.anObject.nested).toMatchObject({yummie: true})34 })35 expect(nextState).toBe(baseState)36 })3738 it("should return a copy when modifying stuff", () => {39 const nextState = produce(baseState, s => {40 s.aProp = "hello world"41 })42 expect(nextState).not.toBe(baseState)43 expect(baseState.aProp).toBe("hi")44 expect(nextState.aProp).toBe("hello world")45 // structural sharing?46 expect(nextState.nested).toBe(baseState.nested)47 })4849 if (50 ("should preserve type",51 () => {52 const nextState = produce(baseState, s => {53 expect(Array.isArray(s)).toBe(true)54 expect(s.protoType).toBe(Object)55 s.anArray.push(3)56 s.aProp = "hello world"57 expect(Array.isArray(s)).toBe(true)58 expect(s.protoType).toBe(Object)59 })60 expect(Array.isArray(nextState)).toBe(true)61 expect(nextState.protoType).toBe(Object)62 })63 )64 it("deep change bubbles up", () => {65 const nextState = produce(baseState, s => {66 s.anObject.nested.yummie = false67 })68 expect(nextState).not.toBe(baseState)69 expect(nextState.anObject).not.toBe(baseState.anObject)70 expect(baseState.anObject.nested.yummie).toBe(true)71 expect(nextState.anObject.nested.yummie).toBe(false)72 expect(nextState.anArray).toBe(baseState.anArray)73 })7475 it("can add props", () => {76 const nextState = produce(baseState, s => {77 s.anObject.cookie = {tasty: true}78 })79 expect(nextState).not.toBe(baseState)80 expect(nextState.anObject).not.toBe(baseState.anObject)81 expect(nextState.anObject.nested).toBe(baseState.anObject.nested)82 expect(nextState.anObject.cookie).toEqual({tasty: true})83 })8485 it("can delete props", () => {86 const nextState = produce(baseState, s => {87 delete s.anObject.nested88 })89 expect(nextState).not.toBe(baseState)90 expect(nextState.anObject).not.toBe(baseState.anObject)91 expect(nextState.anObject.nested).toBe(undefined)92 })9394 it("ignores single non-modification", () => {95 const nextState = produce(baseState, s => {96 s.aProp = "hi"97 })98 expect(nextState).toBe(baseState)99 })100101 it("processes single modification", () => {102 const nextState = produce(baseState, s => {103 s.aProp = "hello"104 s.aProp = "hi"105 })106 expect(nextState).not.toBe(baseState)107 expect(nextState).toEqual(baseState)108 })109110 it("processes with for loop", () => {111 const base = [{id: 1, a: 1}, {id: 2, a: 1}]112 const findById = (collection, id) => {113 for (const item of collection) {114 if (item.id === id) return item115 }116 return null117 }118 const result = produce(base, draft => {119 const obj1 = findById(draft, 1)120 const obj2 = findById(draft, 2)121 obj1.a = 2122 obj2.a = 2123 })124 expect(result[0].a).toEqual(2)125 expect(result[1].a).toEqual(2)126 })127128 it("works with objects without proto", () => {129 const base = Object.create(null)130 base.x = 1131 base.y = Object.create(null)132 base.y.y = 2133 expect(base.__proto__).toBe(undefined)134 const next = produce(base, draft => {135 draft.y.z = 3136 draft.y.y++137 draft.x++138 })139 expect(next).toEqual({140 x: 2,141 y: {y: 3, z: 3}142 })143 expect(next.__proto__).toBe(undefined)144 })145146 it("should support reading arrays", () => {147 const nextState = produce(baseState, s => {148 s.anArray.slice()149 })150 expect(nextState.anArray).toBe(baseState.anArray)151 expect(nextState).toBe(baseState)152 })153154 it("should support changing arrays", () => {155 const nextState = produce(baseState, s => {156 s.anArray[3] = true157 })158 expect(nextState).not.toBe(baseState)159 expect(nextState.anArray).not.toBe(baseState.anArray)160 expect(nextState.anArray[3]).toEqual(true)161 })162163 it("should support changing arrays - 2", () => {164 const nextState = produce(baseState, s => {165 s.anArray.splice(1, 1, "a", "b")166 })167 expect(nextState).not.toBe(baseState)168 expect(nextState.anArray).not.toBe(baseState.anArray)169170 expect(enumerableOnly(nextState.anArray)).toEqual([171 3,172 "a",173 "b",174 {c: 3},175 1176 ])177 })178179 it("can delete array items", () => {180 const nextState = produce(baseState, s => {181 s.anArray.length = 3182 })183 expect(nextState).not.toBe(baseState)184 expect(nextState.anObject).toBe(baseState.anObject)185 expect(nextState.anArray).not.toBe(baseState.anArray)186 expect(nextState.anArray).toEqual([3, 2, {c: 3}])187 })188189 it("should support sorting arrays", () => {190 const nextState = produce(baseState, s => {191 s.anArray[2].c = 4192 s.anArray.sort()193 s.anArray[3].c = 5194 })195 expect(nextState).not.toBe(baseState)196 expect(nextState.anArray).not.toBe(baseState.anArray)197 expect(enumerableOnly(nextState.anArray)).toEqual([1, 2, 3, {c: 5}])198 })199200 it("should expose property descriptors", () => {201 const nextState = produce([], s => {202 expect(Object.getOwnPropertyDescriptor(s, 0)).toBe(undefined)203 s.unshift("x")204 expect(Object.getOwnPropertyDescriptor(s, 0)).toEqual({205 configurable: true,206 enumerable: true,207 value: "x",208 writable: true209 })210 expect(s.length).toBe(1)211 expect(s[0] === "x").toBe(true)212 })213 expect(nextState).toEqual(["x"])214 expect(Object.getOwnPropertyDescriptor(nextState, 0)).toEqual({215 configurable: !freeze,216 enumerable: true,217 value: "x",218 writable: !freeze219 })220 })221222 it("should support sorting arrays - 2", () => {223 const nextState = produce(baseState, s => {224 s.anArray.unshift("x")225 s.anArray[3].c = 4226 s.anArray.sort()227 s.anArray[3].c = 5228 s.anArray.unshift("y")229 })230 expect(nextState).not.toBe(baseState)231 expect(nextState.anArray).not.toBe(baseState.anArray)232 expect(enumerableOnly(nextState.anArray)).toEqual([233 "y",234 1,235 2,236 3,237 {c: 5},238 "x"239 ])240 })241242 it("should updating inside arrays", () => {243 const nextState = produce(baseState, s => {244 s.anArray[2].test = true245 })246 expect(nextState).not.toBe(baseState)247 expect(nextState.anArray).not.toBe(baseState.anArray)248 expect(nextState.anArray).toEqual([3, 2, {c: 3, test: true}, 1])249 })250251 it("reusing object should work", () => {252 const nextState = produce(baseState, s => {253 const obj = s.anObject254 delete s.anObject255 s.messy = obj256 })257 expect(nextState).not.toBe(baseState)258 expect(nextState.anArray).toBe(baseState.anArray)259 expect(enumerableOnly(nextState)).toEqual({260 anArray: [3, 2, {c: 3}, 1],261 aProp: "hi",262 messy: {263 nested: {264 yummie: true265 },266 coffee: false267 }268 })269 expect(nextState.messy.nested).toBe(baseState.anObject.nested)270 })271272 it("refs should be transparent", () => {273 const nextState = produce(baseState, s => {274 const obj = s.anObject275 s.aProp = "hello"276 delete s.anObject277 obj.coffee = true278 s.messy = obj279 })280 expect(nextState).not.toBe(baseState)281 expect(nextState.anArray).toBe(baseState.anArray)282 expect(enumerableOnly(nextState)).toEqual({283 anArray: [3, 2, {c: 3}, 1],284 aProp: "hello",285 messy: {286 nested: {287 yummie: true288 },289 coffee: true290 }291 })292 expect(nextState.messy.nested).toBe(baseState.anObject.nested)293 })294295 it("should allow setting to undefined a defined draft property", () => {296 const nextState = produce(baseState, s => {297 s.aProp = undefined298 })299 expect(nextState).not.toBe(baseState)300 expect(baseState.aProp).toBe("hi")301 expect(nextState.aProp).toBe(undefined)302 })303304 // ES implementation does't protect against all outside modifications, just some..305 if (useProxies) {306 it("should revoke the proxy of the baseState after immer function is executed", () => {307 let proxy308 const nextState = produce(baseState, s => {309 proxy = s310 s.aProp = "hello"311 })312 expect(nextState).not.toBe(baseState)313 expect(baseState.aProp).toBe("hi")314 expect(nextState.aProp).toBe("hello")315316 expect(() => {317 proxy.aProp = "Hallo"318 }).toThrowError(/revoked/)319 expect(() => {320 const aProp = proxy.aProp321 }).toThrowError(/revoked/)322323 expect(nextState).not.toBe(baseState)324 expect(baseState.aProp).toBe("hi")325 expect(nextState.aProp).toBe("hello")326 })327 }328329 it("should revoke the proxy of the baseState after immer function is executed - 2", () => {330 let proxy331 const nextState = produce(baseState, s => {332 proxy = s.anObject333 })334 expect(nextState).toBe(baseState)335 expect(() => {336 // In ES5 implemenation only protects existing props, but alas..337 proxy.coffee = "Hallo"338 }).toThrowError(/revoked/)339 expect(() => {340 const test = proxy.coffee341 }).toThrowError(/revoked/)342 })343344 it("should reflect all changes made in the draft immediately", () => {345 produce(baseState, draft => {346 draft.anArray[0] = 5347 draft.anArray.unshift("test")348 // sliced here; jest will also compare non-enumerable keys, which would include the immer Symbols349 expect(draft.anArray.slice()).toMatchObject([350 "test",351 5,352 2,353 {c: 3},354 1355 ])356 draft.stuffz = "coffee"357 expect(draft.stuffz).toBe("coffee")358 })359 })360361 it("should be able to get property descriptors from objects", () => {362 produce({a: 1}, draft => {363 expect("a" in draft).toBe(true)364 expect("b" in draft).toBe(false)365 expect(366 Reflect.ownKeys(draft).filter(x => typeof x === "string")367 ).toEqual(["a"])368369 expect(370 Object.getOwnPropertyDescriptor(draft, "a")371 ).toMatchObject({372 configurable: true,373 enumerable: true374 })375 draft.a = 2376 expect(377 Object.getOwnPropertyDescriptor(draft, "a")378 ).toMatchObject({379 configurable: true,380 enumerable: true381 })382 expect(383 Object.getOwnPropertyDescriptor(draft, "b")384 ).toBeUndefined()385 draft.b = 2386 expect(387 Object.getOwnPropertyDescriptor(draft, "b")388 ).toMatchObject({389 configurable: true,390 enumerable: true391 })392 expect("a" in draft).toBe(true)393 expect("b" in draft).toBe(true)394 expect(395 Reflect.ownKeys(draft).filter(x => typeof x === "string")396 ).toEqual(["a", "b"])397 })398 })399400 it("should be able to get property descriptors from arrays", () => {401 produce([1], draft => {402 expect(0 in draft).toBe(true)403 expect(1 in draft).toBe(false)404 expect("0" in draft).toBe(true)405 expect("1" in draft).toBe(false)406 expect(length in draft).toBe(true)407 expect(408 Reflect.ownKeys(draft).filter(x => typeof x === "string")409 ).toEqual(["0", "length"])410411 expect(412 Object.getOwnPropertyDescriptor(draft, "length")413 ).toMatchObject({414 configurable: false,415 enumerable: false416 })417 draft[0] = 2418 expect(Object.getOwnPropertyDescriptor(draft, 0)).toMatchObject(419 {420 configurable: true,421 enumerable: true422 }423 )424 expect(Object.getOwnPropertyDescriptor(draft, 0)).toMatchObject(425 {426 configurable: true,427 enumerable: true428 }429 )430 expect(431 Object.getOwnPropertyDescriptor(draft, 1)432 ).toBeUndefined()433 draft[1] = 2434 expect(Object.getOwnPropertyDescriptor(draft, 1)).toMatchObject(435 {436 configurable: true,437 enumerable: true438 }439 )440 expect(441 Reflect.ownKeys(draft).filter(x => typeof x === "string")442 ).toEqual(["0", "1", "length"])443 })444 })445446 if (useProxies === true) {447 it("should not be possible to set property descriptors", () => {448 expect(() => {449 produce({}, draft => {450 Object.defineProperty(draft, "xx", {451 enumerable: true,452 writeable: true,453 value: 2454 })455 })456 }).toThrowError(/not support/)457 })458 }459460 it("should not throw error, see #53 - 1", () => {461 const base = {arr: [{count: 1}, {count: 2}, {count: 3}]}462 const result = produce(base, draft => {463 draft.arr = draft.arr.filter(item => item.count > 2)464 })465 expect(result.arr[0].count).toEqual(3)466 expect(result).toEqual({467 arr: [{count: 3}]468 })469 expect(result.arr[0]).toBe(base.arr[2])470 })471472 it("should not throw error, see #53 - 2", () => {473 const base = {arr: [{count: 1}, {count: 2}, {count: 3}]}474 const result = produce(base, draft => {475 draft.newArr = draft.arr.filter(item => item.count > 2)476 })477 expect(result.newArr[0].count).toEqual(3)478 expect(result.arr).toBe(base.arr)479 expect(result).toEqual({480 arr: [481 {482 count: 1483 },484 {485 count: 2486 },487 {488 count: 3489 }490 ],491 newArr: [492 {493 count: 3494 }495 ]496 })497 expect(result.newArr[0]).toBe(base.arr[2])498 expect(result.arr[2]).toBe(base.arr[2])499 })500501 it("should not throw error, see #53 - 3", () => {502 const base = {arr: [{count: 1}, {count: 2}, {count: 3}]}503 const result = produce(base, draft => {504 draft.newArr = draft.arr.filter(item => item.count > 2)505 delete draft.arr506 })507 expect(result.newArr[0].count).toEqual(3)508 expect(result).toEqual({509 newArr: [{count: 3}]510 })511 expect(result.newArr[0]).toBe(base.arr[2])512 })513514 it("should not throw error, see #53 - 4", () => {515 const base = {bear: {age: 10}}516 const result = produce(base, draft => {517 draft.bear.legs = 4518 draft.room = {elephant: {kiddo: draft.bear}}519 })520 expect(result).toEqual({521 bear: {age: 10, legs: 4},522 room: {elephant: {kiddo: {age: 10, legs: 4}}}523 })524525 const result2 = produce(result, draft => {526 draft.bear.age = 11527 draft.room.elephant.kiddo.legs = 5528 })529 expect(result2).toEqual({530 bear: {age: 11, legs: 4},531 room: {elephant: {kiddo: {age: 10, legs: 5}}}532 })533 })534535 it("should not throw error #78", () => {536 const base = {537 arr: [538 {539 id: "100",540 arr: [{id: "1", no: 1}, {id: "2", no: 2}]541 },542 {id: "3", no: 3}543 ]544 }545 const result = produce(base, draft => {546 const base = draft.arr[0]547 draft.arr = draft.arr.slice(0, 1)548 const newArr = {549 id: "101",550 arr: [base, {id: "3"}]551 }552 draft.arr.splice(0, 1, newArr)553 draft.arr[0].arr[1].no = 3554 })555 expect(result).toEqual({556 arr: [557 {558 id: "101",559 arr: [560 {561 id: "100",562 arr: [{id: "1", no: 1}, {id: "2", no: 2}]563 },564 {id: "3", no: 3}565 ]566 }567 ]568 })569 })570571 it("should not throw error #78 - 2", () => {572 const base = {573 arr: [{count: 1}, {count: 2}]574 }575 const result = produce(base, draft => {576 draft.arr = [draft.arr[1]]577 draft.arr[0].count = 1578 })579 expect(result).toEqual({580 arr: [{count: 1}]581 })582 })583584 it("should handle constructor correctly", () => {585 const base = {586 arr: new Array(),587 obj: new Object()588 }589 const result = produce(base, draft => {590 draft.arrConstructed = draft.arr.constructor(1)591 draft.objConstructed = draft.obj.constructor(1)592 })593 expect(result.arrConstructed).toEqual(new Array().constructor(1))594 expect(result.objConstructed).toEqual(new Object().constructor(1))595 })596597 it("should handle dates correctly", () => {598 const data = {date: new Date()}599 const next = produce(data, draft => {600 draft.x = true601 })602 expect(next).toEqual({x: true, date: data.date})603 expect(next.date).toBe(data.date)604 const next2 = produce(next, draft => {605 draft.date.setYear(2015)606 })607 // This still holds; because produce won't proxy Date objects608 // and the original is actually modified!609 expect(next2).toEqual({x: true, date: data.date})610 expect(next2.date).toBe(next.date)611 expect(next2.date).toBe(data.date)612 expect(next2).toBe(next)613 })614615 it("should handle equality correctly - 1", () => {616 const base = {617 y: 3 / 0,618 z: NaN619 }620 const next = produce(base, draft => {621 draft.y = 4 / 0622 draft.z = NaN623 })624 expect(next).toEqual(base)625 expect(next).toBe(base)626 })627628 it("should handle equality correctly - 2", () => {629 const base = {630 x: -0631 }632 const next = produce(base, draft => {633 draft.x = +1634 })635 expect(next).not.toEqual(base)636 expect(next).not.toBe(base)637 })638639 it("should handle nested immer calls correctly - 1", () => {640 const bear = {paw: {honey: true}}641 const next = produce(bear, draft => {642 const paw2 = produce(bear.paw, draft => {643 draft.honey = false644 })645 expect(paw2.honey).toBe(false)646 expect(draft.paw.honey).toBe(true) // effects should not be visible outside647 })648 expect(next.paw.honey).toBe(true)649 expect(next).toBe(bear)650 })651652 it("should handle nested immer calls correctly - 2", () => {653 const bear = {paw: {honey: true}}654 const next = produce(bear, draft => {655 const paw2 = produce(bear.paw, draft => {656 draft.honey = false657 })658 expect(paw2.honey).toBe(false)659 expect(draft.paw.honey).toBe(true)660 draft.paw = paw2661 expect(draft.paw.honey).toBe(false)662 })663 expect(next.paw.honey).toBe(false)664 expect(next).not.toBe(bear)665 })666667 it("should not try to change immutable data, see #66", () => {668 const user = require("./test-data")669670 const base = {}671 const next = produce(base, draft => {672 draft.user = user673 })674 expect(next.user).toBe(user)675 expect(next).not.toBe(base)676 expect(next.user).toEqual(user)677 })678679 it("should not try to change immutable data, see #66 - 2", () => {680 const user = deepFreeze(cloneDeep(require("./test-data")))681682 const base = {}683 const next = produce(base, draft => {684 draft.user = user685 })686 expect(next.user).toBe(user)687 expect(next).not.toBe(base)688 expect(next.user).toEqual(user)689 })690691 if (freeze)692 it("should freeze new data well", () => {693 const base = {}694 const next = produce(base, draft => {695 draft.x = {y: [{z: true}]}696 })697 expect(Object.isFrozen(next)).toBe(true)698 expect(Object.isFrozen(next.x)).toBe(true)699 expect(Object.isFrozen(next.x.y)).toBe(true)700 expect(Object.isFrozen(next.x.y[0].z)).toBe(true)701 })702703 it("should structurally share identical objects in the tree", () => {704 const base = {bear: {legs: 4}, eagle: {legs: 3}}705 const next = produce(base, draft => {706 const animal = draft.bear707 animal.legs = animal.legs + 1708 draft.bear = animal709 draft.eagle = animal710 draft.cow = animal711 draft.kiddo = animal712 })713 expect(next).toEqual({714 bear: {legs: 5},715 eagle: {legs: 5},716 cow: {legs: 5},717 kiddo: {legs: 5}718 })719 expect(next.bear).toBe(next.cow)720 expect(next.kiddo).toBe(next.cow)721 })722723 if (useProxies)724 it("should not allow changing prototype", () => {725 produce({}, draft => {726 expect(() => Object.setPrototypeOf(draft, Array)).toThrow(727 /try this/728 )729 })730 })731732 it("'in' should work", () => {733 produce(createBaseState(), draft => {734 expect("anArray" in draft).toBe(true)735 expect(Reflect.has(draft, "anArray")).toBe(true)736737 expect("bla" in draft).toBe(false)738 expect(Reflect.has(draft, "bla")).toBe(false)739740 expect(0 in draft.anArray).toBe(true)741 expect("0" in draft.anArray).toBe(true)742 expect(Reflect.has(draft.anArray, 0)).toBe(true)743 expect(Reflect.has(draft.anArray, "0")).toBe(true)744745 expect(17 in draft.anArray).toBe(false)746 expect("17" in draft.anArray).toBe(false)747 expect(Reflect.has(draft.anArray, 17)).toBe(false)748 expect(Reflect.has(draft.anArray, "17")).toBe(false)749 })750 })751752 it("'this' should work - 1", () => {753 const base = {x: 3}754 const next1 = produce(base, function() {755 this.x = 4756 })757 expect(next1).not.toBe(base)758 expect(next1.x).toBe(4)759 })760761 it("'this' should work - 1", () => {762 const base = {x: 3}763 const incrementor = produce(function() {764 this.x = 4765 })766 const next1 = incrementor(base)767 expect(next1).not.toBe(base)768 expect(next1.x).toBe(4)769 })770771 it("issue #89", () => {772 const state = {773 users: {774 existingID: {775 loading: false,776 value: "val"777 }778 }779 }780 const nextState = produce(state, draft => {781 draft.users.existingID = {782 ...draft.users.existingID,783 loading: true784 }785 })786 expect(nextState).toEqual({787 users: {788 existingID: {789 loading: true,790 value: "val"791 }792 }793 })794 })795796 it("processes with lodash.set", () => {797 const base = [{id: 1, a: 1}]798 const result = produce(base, draft => {799 lodash.set(draft, "[0].a", 2)800 })801 expect(base[0].a).toEqual(1)802 expect(result[0].a).toEqual(2)803 })804805 it("processes with lodash.find", () => {806 const base = [{id: 1, a: 1}]807 const result = produce(base, draft => {808 const obj1 = lodash.find(draft, {id: 1})809 lodash.set(obj1, "a", 2)810 })811 expect(base[0].a).toEqual(1)812 expect(result[0].a).toEqual(2)813 })814815 it("can produce from no state", () => {816 expect(817 produce(3, draft => {818 expect(draft).toBe(3)819 return 5820 })821 ).toBe(5)822 })823824 it("can return something new ", () => {825 const base = {x: 3}826 const res = produce(base, draft => {827 return {x: draft.x + 1}828 })829 expect(res).not.toBe(base)830 expect(res).toEqual({x: 4})831 })832833 it("can return the draft new ", () => {834 const base = {x: 3}835 const res = produce(base, draft => {836 draft.x = 4837 return draft838 })839 expect(res).not.toBe(base)840 expect(res).toEqual({x: 4})841 })842843 it("should throw if modifying the draft and returning something new", () => {844 const base = {x: 3}845 expect(() => {846 produce(base, draft => {847 draft.x = 4848 return {x: 5}849 })850 }).toThrow(/An immer producer returned a new value/)851 })852853 it("should fix #116", () => {854 const nextState = produce([1, 2, 3], s => {855 s.pop()856 s.push(100)857 })858 expect(nextState).toEqual([1, 2, 100])859 })860861 afterEach(() => {862 expect(baseState).toBe(origBaseState)863 expect(baseState).toEqual(createBaseState())864 })865866 function createBaseState() {867 const data = {868 anArray: [3, 2, {c: 3}, 1],869 aProp: "hi",870 anObject: {871 nested: {872 yummie: true873 },874 coffee: false875 }876 }877 return freeze ? deepFreeze(data) : data878 }879 })880}881882function enumerableOnly(x) {883 // this can be done better...884 return JSON.parse(JSON.stringify(x))885}