Skip to content
Myr

feat: `onCopy` for `Maps`

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by keenondrums · committed by Alec Larson · parent 1ca49ef · Browse files · 1 file+17 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+17 added−3 removed

  • tests:+17 added−3 removed

1 file+17 added−3 removed

modified:__tests__/hooks.js+17 added-3 removed
247 unmodified lines
248 }249 })250251 describe("onCopy()", () => {252 useSharedTests(() => onCopy)253 it("is called in the right order", () => {254 const calls = []252 let calls253 beforeEach(() => {254 calls = []255 onCopy.mockImplementation(s => {256 calls.push(s.base)257 })258 })259260 useSharedTests(() => onCopy)261 it("is called in the right order for objects", () => {262 const base = {a: {b: {c: 1}}}263 produce(base, s => {264 delete s.a.b.c265 })266 expect(calls).toShallowEqual([base.a.b, base.a, base])267 })268269 if (useProxies) {270 it("is called in the right order for Maps", () => {271 const base = new Map([["a", new Map([["b", 0]])]])272 produce(base, s => {273 s.get("a").delete("b")274 })275 expect(calls).toShallowEqual([base.get("a"), base])276 })277 }278 })279280 function useSharedTests(getHook) {281 it("is called before the parent is frozen", () => {
43 unmodified lines