cross-state 0.37.3 → 0.37.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../../src/patches/patchMethods.ts"],"sourcesContent":["import type { SubscribeOptions } from '@core';\nimport type { Store } from '@core/store';\nimport { applyPatches as _applyPatches } from '@lib/applyPatches';\nimport { diff, type DiffOptions, type Patch } from '@lib/diff';\n\ndeclare module '@core' {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Store<T> {\n __patches?: Store<[Patch[], Patch[]]>;\n }\n}\n\nexport interface SubscribePatchOptions extends SubscribeOptions, DiffOptions {\n /** @default false */\n runNow?: boolean;\n}\n\nexport interface SyncMessage {\n id: string;\n previousId?: string;\n patches: Patch[];\n}\n\nexport type InteropPatch = Patch | { op: 'add' | 'replace' | 'remove'; value?: any };\n\nconst genId = () => Math.random().toString(36).slice(2);\n\nfunction subscribePatches<T>(\n this: Store<T>,\n listener: (patches: Patch[], reversePatches: Patch[]) => void,\n options?: SubscribePatchOptions,\n) {\n if (!this.__patches) {\n let previousValue = this.get();\n\n this.__patches = this.map((value) => {\n const result = diff(previousValue, value, options);\n previousValue = value;\n return result;\n });\n }\n\n const { stopAt, runNow, ...subscribeOptions } = options ?? {};\n\n const cancel = this.__patches.subscribe((p) => listener(...p), subscribeOptions);\n\n if (runNow) {\n listener(...diff(undefined, this.get(), options));\n }\n\n return cancel;\n}\n\nfunction applyPatches<T>(this: Store<T>, patches: InteropPatch[]): void;\nfunction applyPatches<T>(this: Store<T>, ...patches: InteropPatch[]): void;\nfunction applyPatches<T>(this: Store<T>, ...patches: (InteropPatch | InteropPatch[])[]): void {\n this.set((value) => _applyPatches(value, ...(patches.flat() as Patch[])));\n}\n\nfunction sync<T>(\n this: Store<T>,\n listener: (syncMessage: SyncMessage) => void,\n options?: Omit<SubscribePatchOptions, 'runNow'>,\n) {\n let previousId: string | undefined;\n\n return this.subscribePatches(\n (patches) => {\n const id = genId();\n const message = { id, previousId, patches };\n previousId = id;\n\n listener(message);\n },\n { ...options, runNow: true },\n );\n}\n\nfunction acceptSync<T>(this: Store<T>) {\n let previousId: string | undefined;\n\n return (message: SyncMessage) => {\n if (message.previousId && message.previousId !== previousId) {\n throw new Error('previousId mismatch');\n }\n\n previousId = message.id;\n this.applyPatches(...message.patches);\n };\n}\n\nexport const patchMethods = {\n subscribePatches,\n applyPatches,\n sync,\n acceptSync,\n};\n"],"names":["diff","_applyPatches"],"mappings":";;;AAyBA,MAAM,QAAQ,MAAM,KAAK,SAAS,SAAS,EAAE,EAAE,MAAM,CAAC;AAEtD,SAAS,iBAEP,UACA,SACA;AACI,MAAA,CAAC,KAAK,WAAW;AACf,QAAA,gBAAgB,KAAK;AAEzB,SAAK,YAAY,KAAK,IAAI,CAAC,UAAU;AACnC,YAAM,SAASA,KAAA,KAAK,eAAe,OAAO,OAAO;AACjC,sBAAA;AACT,aAAA;AAAA,IAAA,CACR;AAAA,EACH;AAEA,QAAM,EAAE,QAAQ,QAAQ,GAAG,iBAAiB,IAAI,WAAW;AAErD,QAAA,SAAS,KAAK,UAAU,UAAU,CAAC,MAAM,SAAS,GAAG,CAAC,GAAG,gBAAgB;AAE/E,MAAI,QAAQ;AACV,aAAS,GAAGA,KAAK,KAAA,QAAW,KAAK,IAAI,GAAG,OAAO,CAAC;AAAA,EAClD;AAEO,SAAA;AACT;AAIA,SAAS,gBAAmC,SAAkD;AACvF,OAAA,IAAI,CAAC,UAAUC,KAAA,aAAc,OAAO,GAAI,QAAQ,KAAkB,CAAA,CAAC;AAC1E;AAEA,SAAS,KAEP,UACA,SACA;AACI,MAAA;AAEJ,SAAO,KAAK;AAAA,IACV,CAAC,YAAY;AACX,YAAM,KAAK;AACX,YAAM,UAAU,EAAE,IAAI,YAAY,QAAQ;AAC7B,mBAAA;AAEb,eAAS,OAAO;AAAA,IAClB;AAAA,IACA,EAAE,GAAG,SAAS,QAAQ,KAAK;AAAA,EAAA;AAE/B;AAEA,SAAS,aAA8B;AACjC,MAAA;AAEJ,SAAO,CAAC,YAAyB;AAC/B,QAAI,QAAQ,cAAc,QAAQ,eAAe,YAAY;AACrD,YAAA,IAAI,MAAM,qBAAqB;AAAA,IACvC;AAEA,iBAAa,QAAQ;AAChB,SAAA,aAAa,GAAG,QAAQ,OAAO;AAAA,EAAA;AAExC;AAEO,MAAM,eAAe;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../../../src/patches/patchMethods.ts"],"sourcesContent":["import type { Cancel, SubscribeOptions } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport { applyPatches as _applyPatches } from '@lib/applyPatches';\nimport { diff, type DiffOptions, type Patch } from '@lib/diff';\n\ndeclare module '@core' {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Store<T> {\n __patches?: Store<[Patch[], Patch[]]>;\n }\n}\n\nexport interface SubscribePatchOptions extends SubscribeOptions, DiffOptions {\n /** @default false */\n runNow?: boolean;\n}\n\nexport interface SyncMessage {\n id: string;\n previousId?: string;\n patches: Patch[];\n}\n\nexport type InteropPatch = Patch | { op: 'add' | 'replace' | 'remove'; value?: any };\n\nconst genId = () => Math.random().toString(36).slice(2);\n\nfunction subscribePatches<T>(\n this: Store<T>,\n listener: (patches: Patch[], reversePatches: Patch[]) => void,\n options?: SubscribePatchOptions,\n): Cancel {\n if (!this.__patches) {\n let previousValue = this.get();\n\n this.__patches = this.map((value) => {\n const result = diff(previousValue, value, options);\n previousValue = value;\n return result;\n });\n }\n\n const { stopAt, runNow, ...subscribeOptions } = options ?? {};\n\n const cancel = this.__patches.subscribe((p) => listener(...p), subscribeOptions);\n\n if (runNow) {\n listener(...diff(undefined, this.get(), options));\n }\n\n return cancel;\n}\n\nfunction applyPatches<T>(this: Store<T>, patches: InteropPatch[]): void;\nfunction applyPatches<T>(this: Store<T>, ...patches: InteropPatch[]): void;\nfunction applyPatches<T>(this: Store<T>, ...patches: (InteropPatch | InteropPatch[])[]): void {\n this.set((value) => _applyPatches(value, ...(patches.flat() as Patch[])));\n}\n\nfunction sync<T>(\n this: Store<T>,\n listener: (syncMessage: SyncMessage) => void,\n options?: Omit<SubscribePatchOptions, 'runNow'>,\n): Cancel {\n let previousId: string | undefined;\n\n return this.subscribePatches(\n (patches) => {\n const id = genId();\n const message = { id, previousId, patches };\n previousId = id;\n\n listener(message);\n },\n { ...options, runNow: true },\n );\n}\n\nfunction acceptSync<T>(this: Store<T>): (message: SyncMessage) => void {\n let previousId: string | undefined;\n\n return (message) => {\n if (message.previousId && message.previousId !== previousId) {\n throw new Error('previousId mismatch');\n }\n\n previousId = message.id;\n this.applyPatches(...message.patches);\n };\n}\n\nexport const patchMethods = {\n subscribePatches,\n applyPatches,\n sync,\n acceptSync,\n};\n"],"names":["diff","_applyPatches"],"mappings":";;;AAyBA,MAAM,QAAQ,MAAM,KAAK,SAAS,SAAS,EAAE,EAAE,MAAM,CAAC;AAEtD,SAAS,iBAEP,UACA,SACQ;AACJ,MAAA,CAAC,KAAK,WAAW;AACf,QAAA,gBAAgB,KAAK;AAEzB,SAAK,YAAY,KAAK,IAAI,CAAC,UAAU;AACnC,YAAM,SAASA,KAAA,KAAK,eAAe,OAAO,OAAO;AACjC,sBAAA;AACT,aAAA;AAAA,IAAA,CACR;AAAA,EACH;AAEA,QAAM,EAAE,QAAQ,QAAQ,GAAG,iBAAiB,IAAI,WAAW;AAErD,QAAA,SAAS,KAAK,UAAU,UAAU,CAAC,MAAM,SAAS,GAAG,CAAC,GAAG,gBAAgB;AAE/E,MAAI,QAAQ;AACV,aAAS,GAAGA,KAAK,KAAA,QAAW,KAAK,IAAI,GAAG,OAAO,CAAC;AAAA,EAClD;AAEO,SAAA;AACT;AAIA,SAAS,gBAAmC,SAAkD;AACvF,OAAA,IAAI,CAAC,UAAUC,KAAA,aAAc,OAAO,GAAI,QAAQ,KAAkB,CAAA,CAAC;AAC1E;AAEA,SAAS,KAEP,UACA,SACQ;AACJ,MAAA;AAEJ,SAAO,KAAK;AAAA,IACV,CAAC,YAAY;AACX,YAAM,KAAK;AACX,YAAM,UAAU,EAAE,IAAI,YAAY,QAAQ;AAC7B,mBAAA;AAEb,eAAS,OAAO;AAAA,IAClB;AAAA,IACA,EAAE,GAAG,SAAS,QAAQ,KAAK;AAAA,EAAA;AAE/B;AAEA,SAAS,aAA8D;AACjE,MAAA;AAEJ,SAAO,CAAC,YAAY;AAClB,QAAI,QAAQ,cAAc,QAAQ,eAAe,YAAY;AACrD,YAAA,IAAI,MAAM,qBAAqB;AAAA,IACvC;AAEA,iBAAa,QAAQ;AAChB,SAAA,aAAa,GAAG,QAAQ,OAAO;AAAA,EAAA;AAExC;AAEO,MAAM,eAAe;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../src/patches/patchMethods.ts"],"sourcesContent":["import type { SubscribeOptions } from '@core';\nimport type { Store } from '@core/store';\nimport { applyPatches as _applyPatches } from '@lib/applyPatches';\nimport { diff, type DiffOptions, type Patch } from '@lib/diff';\n\ndeclare module '@core' {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Store<T> {\n __patches?: Store<[Patch[], Patch[]]>;\n }\n}\n\nexport interface SubscribePatchOptions extends SubscribeOptions, DiffOptions {\n /** @default false */\n runNow?: boolean;\n}\n\nexport interface SyncMessage {\n id: string;\n previousId?: string;\n patches: Patch[];\n}\n\nexport type InteropPatch = Patch | { op: 'add' | 'replace' | 'remove'; value?: any };\n\nconst genId = () => Math.random().toString(36).slice(2);\n\nfunction subscribePatches<T>(\n this: Store<T>,\n listener: (patches: Patch[], reversePatches: Patch[]) => void,\n options?: SubscribePatchOptions,\n) {\n if (!this.__patches) {\n let previousValue = this.get();\n\n this.__patches = this.map((value) => {\n const result = diff(previousValue, value, options);\n previousValue = value;\n return result;\n });\n }\n\n const { stopAt, runNow, ...subscribeOptions } = options ?? {};\n\n const cancel = this.__patches.subscribe((p) => listener(...p), subscribeOptions);\n\n if (runNow) {\n listener(...diff(undefined, this.get(), options));\n }\n\n return cancel;\n}\n\nfunction applyPatches<T>(this: Store<T>, patches: InteropPatch[]): void;\nfunction applyPatches<T>(this: Store<T>, ...patches: InteropPatch[]): void;\nfunction applyPatches<T>(this: Store<T>, ...patches: (InteropPatch | InteropPatch[])[]): void {\n this.set((value) => _applyPatches(value, ...(patches.flat() as Patch[])));\n}\n\nfunction sync<T>(\n this: Store<T>,\n listener: (syncMessage: SyncMessage) => void,\n options?: Omit<SubscribePatchOptions, 'runNow'>,\n) {\n let previousId: string | undefined;\n\n return this.subscribePatches(\n (patches) => {\n const id = genId();\n const message = { id, previousId, patches };\n previousId = id;\n\n listener(message);\n },\n { ...options, runNow: true },\n );\n}\n\nfunction acceptSync<T>(this: Store<T>) {\n let previousId: string | undefined;\n\n return (message: SyncMessage) => {\n if (message.previousId && message.previousId !== previousId) {\n throw new Error('previousId mismatch');\n }\n\n previousId = message.id;\n this.applyPatches(...message.patches);\n };\n}\n\nexport const patchMethods = {\n subscribePatches,\n applyPatches,\n sync,\n acceptSync,\n};\n"],"names":["_applyPatches"],"mappings":";AAyBA,MAAM,QAAQ,MAAM,KAAK,SAAS,SAAS,EAAE,EAAE,MAAM,CAAC;AAEtD,SAAS,iBAEP,UACA,SACA;AACI,MAAA,CAAC,KAAK,WAAW;AACf,QAAA,gBAAgB,KAAK;AAEzB,SAAK,YAAY,KAAK,IAAI,CAAC,UAAU;AACnC,YAAM,SAAS,KAAK,eAAe,OAAO,OAAO;AACjC,sBAAA;AACT,aAAA;AAAA,IAAA,CACR;AAAA,EACH;AAEA,QAAM,EAAE,QAAQ,QAAQ,GAAG,iBAAiB,IAAI,WAAW;AAErD,QAAA,SAAS,KAAK,UAAU,UAAU,CAAC,MAAM,SAAS,GAAG,CAAC,GAAG,gBAAgB;AAE/E,MAAI,QAAQ;AACV,aAAS,GAAG,KAAK,QAAW,KAAK,IAAI,GAAG,OAAO,CAAC;AAAA,EAClD;AAEO,SAAA;AACT;AAIA,SAAS,gBAAmC,SAAkD;AACvF,OAAA,IAAI,CAAC,UAAUA,eAAc,OAAO,GAAI,QAAQ,KAAkB,CAAA,CAAC;AAC1E;AAEA,SAAS,KAEP,UACA,SACA;AACI,MAAA;AAEJ,SAAO,KAAK;AAAA,IACV,CAAC,YAAY;AACX,YAAM,KAAK;AACX,YAAM,UAAU,EAAE,IAAI,YAAY,QAAQ;AAC7B,mBAAA;AAEb,eAAS,OAAO;AAAA,IAClB;AAAA,IACA,EAAE,GAAG,SAAS,QAAQ,KAAK;AAAA,EAAA;AAE/B;AAEA,SAAS,aAA8B;AACjC,MAAA;AAEJ,SAAO,CAAC,YAAyB;AAC/B,QAAI,QAAQ,cAAc,QAAQ,eAAe,YAAY;AACrD,YAAA,IAAI,MAAM,qBAAqB;AAAA,IACvC;AAEA,iBAAa,QAAQ;AAChB,SAAA,aAAa,GAAG,QAAQ,OAAO;AAAA,EAAA;AAExC;AAEO,MAAM,eAAe;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/patches/patchMethods.ts"],"sourcesContent":["import type { Cancel, SubscribeOptions } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport { applyPatches as _applyPatches } from '@lib/applyPatches';\nimport { diff, type DiffOptions, type Patch } from '@lib/diff';\n\ndeclare module '@core' {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Store<T> {\n __patches?: Store<[Patch[], Patch[]]>;\n }\n}\n\nexport interface SubscribePatchOptions extends SubscribeOptions, DiffOptions {\n /** @default false */\n runNow?: boolean;\n}\n\nexport interface SyncMessage {\n id: string;\n previousId?: string;\n patches: Patch[];\n}\n\nexport type InteropPatch = Patch | { op: 'add' | 'replace' | 'remove'; value?: any };\n\nconst genId = () => Math.random().toString(36).slice(2);\n\nfunction subscribePatches<T>(\n this: Store<T>,\n listener: (patches: Patch[], reversePatches: Patch[]) => void,\n options?: SubscribePatchOptions,\n): Cancel {\n if (!this.__patches) {\n let previousValue = this.get();\n\n this.__patches = this.map((value) => {\n const result = diff(previousValue, value, options);\n previousValue = value;\n return result;\n });\n }\n\n const { stopAt, runNow, ...subscribeOptions } = options ?? {};\n\n const cancel = this.__patches.subscribe((p) => listener(...p), subscribeOptions);\n\n if (runNow) {\n listener(...diff(undefined, this.get(), options));\n }\n\n return cancel;\n}\n\nfunction applyPatches<T>(this: Store<T>, patches: InteropPatch[]): void;\nfunction applyPatches<T>(this: Store<T>, ...patches: InteropPatch[]): void;\nfunction applyPatches<T>(this: Store<T>, ...patches: (InteropPatch | InteropPatch[])[]): void {\n this.set((value) => _applyPatches(value, ...(patches.flat() as Patch[])));\n}\n\nfunction sync<T>(\n this: Store<T>,\n listener: (syncMessage: SyncMessage) => void,\n options?: Omit<SubscribePatchOptions, 'runNow'>,\n): Cancel {\n let previousId: string | undefined;\n\n return this.subscribePatches(\n (patches) => {\n const id = genId();\n const message = { id, previousId, patches };\n previousId = id;\n\n listener(message);\n },\n { ...options, runNow: true },\n );\n}\n\nfunction acceptSync<T>(this: Store<T>): (message: SyncMessage) => void {\n let previousId: string | undefined;\n\n return (message) => {\n if (message.previousId && message.previousId !== previousId) {\n throw new Error('previousId mismatch');\n }\n\n previousId = message.id;\n this.applyPatches(...message.patches);\n };\n}\n\nexport const patchMethods = {\n subscribePatches,\n applyPatches,\n sync,\n acceptSync,\n};\n"],"names":["_applyPatches"],"mappings":";AAyBA,MAAM,QAAQ,MAAM,KAAK,SAAS,SAAS,EAAE,EAAE,MAAM,CAAC;AAEtD,SAAS,iBAEP,UACA,SACQ;AACJ,MAAA,CAAC,KAAK,WAAW;AACf,QAAA,gBAAgB,KAAK;AAEzB,SAAK,YAAY,KAAK,IAAI,CAAC,UAAU;AACnC,YAAM,SAAS,KAAK,eAAe,OAAO,OAAO;AACjC,sBAAA;AACT,aAAA;AAAA,IAAA,CACR;AAAA,EACH;AAEA,QAAM,EAAE,QAAQ,QAAQ,GAAG,iBAAiB,IAAI,WAAW;AAErD,QAAA,SAAS,KAAK,UAAU,UAAU,CAAC,MAAM,SAAS,GAAG,CAAC,GAAG,gBAAgB;AAE/E,MAAI,QAAQ;AACV,aAAS,GAAG,KAAK,QAAW,KAAK,IAAI,GAAG,OAAO,CAAC;AAAA,EAClD;AAEO,SAAA;AACT;AAIA,SAAS,gBAAmC,SAAkD;AACvF,OAAA,IAAI,CAAC,UAAUA,eAAc,OAAO,GAAI,QAAQ,KAAkB,CAAA,CAAC;AAC1E;AAEA,SAAS,KAEP,UACA,SACQ;AACJ,MAAA;AAEJ,SAAO,KAAK;AAAA,IACV,CAAC,YAAY;AACX,YAAM,KAAK;AACX,YAAM,UAAU,EAAE,IAAI,YAAY,QAAQ;AAC7B,mBAAA;AAEb,eAAS,OAAO;AAAA,IAClB;AAAA,IACA,EAAE,GAAG,SAAS,QAAQ,KAAK;AAAA,EAAA;AAE/B;AAEA,SAAS,aAA8D;AACjE,MAAA;AAEJ,SAAO,CAAC,YAAY;AAClB,QAAI,QAAQ,cAAc,QAAQ,eAAe,YAAY;AACrD,YAAA,IAAI,MAAM,qBAAqB;AAAA,IACvC;AAEA,iBAAa,QAAQ;AAChB,SAAA,aAAa,GAAG,QAAQ,OAAO;AAAA,EAAA;AAExC;AAEO,MAAM,eAAe;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;"}
@@ -1,4 +1,4 @@
1
- import type { SubscribeOptions } from '../core';
1
+ import type { Cancel, SubscribeOptions } from '../core/commonTypes';
2
2
  import type { Store } from '../core/store';
3
3
  import { type DiffOptions, type Patch } from '../lib/diff';
4
4
  declare module '../core' {
@@ -19,10 +19,10 @@ export type InteropPatch = Patch | {
19
19
  op: 'add' | 'replace' | 'remove';
20
20
  value?: any;
21
21
  };
22
- declare function subscribePatches<T>(this: Store<T>, listener: (patches: Patch[], reversePatches: Patch[]) => void, options?: SubscribePatchOptions): import("../core").DisposableCancel;
22
+ declare function subscribePatches<T>(this: Store<T>, listener: (patches: Patch[], reversePatches: Patch[]) => void, options?: SubscribePatchOptions): Cancel;
23
23
  declare function applyPatches<T>(this: Store<T>, patches: InteropPatch[]): void;
24
24
  declare function applyPatches<T>(this: Store<T>, ...patches: InteropPatch[]): void;
25
- declare function sync<T>(this: Store<T>, listener: (syncMessage: SyncMessage) => void, options?: Omit<SubscribePatchOptions, 'runNow'>): import("../core").DisposableCancel;
25
+ declare function sync<T>(this: Store<T>, listener: (syncMessage: SyncMessage) => void, options?: Omit<SubscribePatchOptions, 'runNow'>): Cancel;
26
26
  declare function acceptSync<T>(this: Store<T>): (message: SyncMessage) => void;
27
27
  export declare const patchMethods: {
28
28
  subscribePatches: typeof subscribePatches;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cross-state",
3
- "version": "0.37.3",
3
+ "version": "0.37.4",
4
4
  "description": "(React) state library",
5
5
  "license": "ISC",
6
6
  "repository": "schummar/cross-state",