{"version":3,"file":"mutativeMethods-AiKkraqx.cjs","names":[],"sources":["../src/mutative/mutativeMethods.ts"],"sourcesContent":["import type { Store } from '@core/store';\nimport type { Constrain } from '@lib/constrain';\nimport { type Path, type Value } from '@lib/path';\nimport { create, type Draft } from 'mutative';\n\nexport type Mutation<T> = (draft: Draft<T>) => void;\n\nfunction update<T>(this: Store<T>, mutation: Mutation<T>): void;\n\nfunction update<T, const P>(\n  this: Store<T>,\n  path: Constrain<P, Path<T>>,\n  mutation: Mutation<Value<T, P>>,\n): void;\n\nfunction update<T, const TPath>(\n  this: Store<T>,\n  ...args:\n    | [recipe: Mutation<T>]\n    | [path: Constrain<TPath, Path<T>>, mutation: Mutation<Value<T, TPath>>]\n) {\n  if (args.length === 1) {\n    const [mutation] = args;\n\n    this.set((value) => {\n      const result = create(value, (draft) => {\n        mutation(draft);\n      });\n      return result;\n    });\n  } else {\n    const [path, mutation] = args;\n\n    this.set(path, (value) => {\n      const result = create(value, (draft) => {\n        mutation(draft);\n      });\n      return result;\n    });\n  }\n}\n\nexport const mutativeMethods: {\n  update: typeof update;\n} = {\n  update,\n};\n"],"mappings":";;;AAeA,SAAS,OAEP,GAAG,MAGH;CACA,IAAI,KAAK,WAAW,GAAG;EACrB,MAAM,CAAC,YAAY;EAEnB,KAAK,KAAK,UAAU;GAIlB,4BAHsB,QAAQ,UAAU;IACtC,SAAS,KAAK;GAChB,CACY;EACd,CAAC;CACH,OAAO;EACL,MAAM,CAAC,MAAM,YAAY;EAEzB,KAAK,IAAI,OAAO,UAAU;GAIxB,4BAHsB,QAAQ,UAAU;IACtC,SAAS,KAAK;GAChB,CACY;EACd,CAAC;CACH;AACF;AAEA,MAAa,kBAET,EACF,OACF"}