atom.io 0.42.0 → 0.42.2
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.
- package/dist/internal/index.d.ts +9 -9
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +46 -36
- package/dist/internal/index.js.map +1 -1
- package/dist/main/index.d.ts +34 -20
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +32 -6
- package/dist/main/index.js.map +1 -1
- package/dist/transceivers/o-list/index.d.ts +6 -1
- package/dist/transceivers/o-list/index.d.ts.map +1 -1
- package/dist/transceivers/o-list/index.js +88 -2
- package/dist/transceivers/o-list/index.js.map +1 -1
- package/dist/transceivers/u-list/index.d.ts +5 -1
- package/dist/transceivers/u-list/index.d.ts.map +1 -1
- package/dist/transceivers/u-list/index.js +33 -2
- package/dist/transceivers/u-list/index.js.map +1 -1
- package/package.json +17 -17
- package/src/internal/atom/create-regular-atom.ts +3 -1
- package/src/internal/join/join-internal.ts +18 -47
- package/src/internal/molecule.ts +44 -25
- package/src/internal/mutable/create-mutable-atom.ts +15 -11
- package/src/internal/store/store.ts +15 -14
- package/src/internal/transaction/build-transaction.ts +1 -1
- package/src/main/atom.ts +15 -6
- package/src/main/realm.ts +54 -13
- package/src/transceivers/o-list/index.ts +1 -0
- package/src/transceivers/o-list/o-list-disposed-key-cleanup-effect.ts +153 -0
- package/src/transceivers/u-list/index.ts +1 -0
- package/src/transceivers/u-list/u-list-disposed-key-cleanup-effect.ts +47 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["ARRAY_UPDATE_ENUM: Enumeration<typeof ARRAY_UPDATES>","prev: P | undefined","result: number","value: P | undefined","prev: P[] | undefined"],"sources":["../../../src/transceivers/o-list/o-list.ts"],"sourcesContent":["import type { Fn, Transceiver, TransceiverMode } from \"atom.io/internal\"\nimport { Subject } from \"atom.io/internal\"\nimport type { primitive } from \"atom.io/json\"\nimport type { Enumeration } from \"atom.io/struct\"\nimport { enumeration, packValue, unpackValue } from \"atom.io/struct\"\n\nexport type ArrayMutations = Exclude<keyof Array<any>, keyof ReadonlyArray<any>>\nexport type ArrayUpdate<P extends primitive> =\n\t| {\n\t\t\ttype: `copyWithin`\n\t\t\ttarget: number\n\t\t\tstart: number\n\t\t\tend?: number\n\t\t\tprev: readonly P[]\n\t }\n\t| {\n\t\t\ttype: `extend`\n\t\t\tnext: number\n\t\t\tprev: number\n\t }\n\t| {\n\t\t\ttype: `fill`\n\t\t\tvalue: P\n\t\t\tstart?: number\n\t\t\tend?: number\n\t\t\tprev: readonly P[]\n\t }\n\t| {\n\t\t\ttype: `pop` | `shift`\n\t\t\tvalue?: P\n\t }\n\t| {\n\t\t\ttype: `push` | `unshift`\n\t\t\titems: readonly P[]\n\t }\n\t| {\n\t\t\ttype: `reverse`\n\t }\n\t| {\n\t\t\ttype: `set`\n\t\t\tnext: P\n\t\t\tprev?: P\n\t\t\tindex: number\n\t }\n\t| {\n\t\t\ttype: `sort`\n\t\t\tnext: readonly P[]\n\t\t\tprev: readonly P[]\n\t }\n\t| {\n\t\t\ttype: `splice`\n\t\t\tstart: number\n\t\t\tdeleteCount: number\n\t\t\titems: readonly P[]\n\t\t\tdeleted: readonly P[]\n\t }\n\t| {\n\t\t\ttype: `truncate`\n\t\t\tlength: number\n\t\t\titems: readonly P[]\n\t }\nexport type OListUpdateType = ArrayUpdate<any>[`type`]\ntrue satisfies ArrayMutations extends OListUpdateType\n\t? true\n\t: Exclude<ArrayMutations, OListUpdateType>\n\nexport type PackedArrayUpdate<P extends primitive> = string & {\n\tupdate?: ArrayUpdate<P>\n\ttype?: P\n}\n\nconst ARRAY_UPDATES = [\n\t// virtual methods\n\t`set`,\n\t`truncate`,\n\t`extend`,\n\t// actual methods\n\t`pop`,\n\t`push`,\n\t`shift`,\n\t`unshift`,\n\t`copyWithin`,\n\t`fill`,\n\t`splice`,\n\t`reverse`,\n\t`sort`,\n] as const\ntrue satisfies ArrayUpdate<any>[`type`] extends (typeof ARRAY_UPDATES)[number]\n\t? true\n\t: Exclude<ArrayUpdate<any>[`type`], (typeof ARRAY_UPDATES)[number]>\n\nexport const ARRAY_UPDATE_ENUM: Enumeration<typeof ARRAY_UPDATES> =\n\tenumeration(ARRAY_UPDATES)\n\nexport type ArrayMutationHandler = {\n\t[K in Exclude<OListUpdateType, `extend` | `set` | `truncate`>]: Fn\n}\n\nexport type OListView<P extends primitive> = ReadonlyArray<P> & {\n\tsubscribe: (\n\t\tkey: string,\n\t\tfn: (update: PackedArrayUpdate<P>) => void,\n\t) => () => void\n}\n\nexport class OList<P extends primitive>\n\textends Array<P>\n\timplements\n\t\tTransceiver<OListView<P>, PackedArrayUpdate<P>, ReadonlyArray<P>>,\n\t\tArrayMutationHandler\n{\n\tpublic mode: TransceiverMode = `record`\n\tpublic readonly subject: Subject<PackedArrayUpdate<P>> = new Subject()\n\n\tpublic readonly READONLY_VIEW: OListView<P> = this\n\n\tpublic constructor(arrayLength?: number)\n\tpublic constructor(...items: P[])\n\tpublic constructor(...items: P[]) {\n\t\tsuper(...items)\n\t\t// biome-ignore lint/correctness/noConstructorReturn: this is chill\n\t\treturn new Proxy(this, {\n\t\t\tset: (target, prop, value, receiver) => {\n\t\t\t\tif (\n\t\t\t\t\ttypeof prop === `string` &&\n\t\t\t\t\t!Number.isNaN(Number.parseInt(prop, 10))\n\t\t\t\t) {\n\t\t\t\t\tconst index = Number(prop)\n\t\t\t\t\tlet prev: P | undefined\n\t\t\t\t\tif (this.mode === `record`) {\n\t\t\t\t\t\tprev = target[index]\n\t\t\t\t\t}\n\t\t\t\t\ttarget[index] = value\n\t\t\t\t\tif (prev) {\n\t\t\t\t\t\tthis.emit({ type: `set`, index, next: value, prev })\n\t\t\t\t\t} else if (this.mode === `record`) {\n\t\t\t\t\t\tthis.emit({ type: `set`, index, next: value })\n\t\t\t\t\t}\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\tif (prop === `length`) {\n\t\t\t\t\tif (this.mode === `record`) {\n\t\t\t\t\t\tconst prevLength = target.length\n\t\t\t\t\t\tif (prevLength === value) return true\n\t\t\t\t\t\tif (prevLength > value) {\n\t\t\t\t\t\t\tconst dropped = target.slice(value)\n\t\t\t\t\t\t\ttarget.length = value\n\t\t\t\t\t\t\tthis.emit({ type: `truncate`, length: value, items: dropped })\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\ttarget.length = value\n\t\t\t\t\t\t\tthis.emit({ type: `extend`, next: value, prev: prevLength })\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttarget.length = value\n\t\t\t\t\t}\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\treturn Reflect.set(target, prop, value, receiver)\n\t\t\t},\n\t\t})\n\t}\n\n\tpublic toJSON(): ReadonlyArray<P> {\n\t\treturn [...this]\n\t}\n\n\tpublic static fromJSON<P extends primitive>(json: ReadonlyArray<P>): OList<P> {\n\t\treturn new OList<P>(...json)\n\t}\n\n\tpublic push(...items: P[]): number {\n\t\tlet result: number\n\t\tif (this.mode === `record`) {\n\t\t\tthis.mode = `playback`\n\t\t\tresult = super.push(...items)\n\t\t\tthis.mode = `record`\n\t\t\tthis.emit({ type: `push`, items })\n\t\t} else {\n\t\t\tresult = super.push(...items)\n\t\t}\n\t\treturn result\n\t}\n\tpublic pop(): P | undefined {\n\t\tlet value: P | undefined\n\t\tif (this.mode === `record`) {\n\t\t\tthis.mode = `playback`\n\t\t\tvalue = super.pop()\n\t\t\tif (value === undefined) {\n\t\t\t\tthis.emit({ type: `pop` })\n\t\t\t} else {\n\t\t\t\tthis.emit({ type: `pop`, value })\n\t\t\t}\n\t\t\tthis.mode = `record`\n\t\t} else {\n\t\t\tvalue = super.pop()\n\t\t}\n\t\treturn value\n\t}\n\tpublic shift(): P | undefined {\n\t\tlet value: P | undefined\n\t\tif (this.mode === `record`) {\n\t\t\tthis.mode = `playback`\n\t\t\tvalue = super.shift()\n\t\t\tif (value === undefined) {\n\t\t\t\tthis.emit({ type: `shift` })\n\t\t\t} else {\n\t\t\t\tthis.emit({ type: `shift`, value })\n\t\t\t}\n\t\t\tthis.mode = `record`\n\t\t} else {\n\t\t\tvalue = super.shift()\n\t\t}\n\t\treturn value\n\t}\n\tpublic unshift(...items: P[]): number {\n\t\tlet result: number\n\t\tif (this.mode === `record`) {\n\t\t\tthis.mode = `playback`\n\t\t\tresult = super.unshift(...items)\n\t\t\tthis.emit({ type: `unshift`, items })\n\t\t\tthis.mode = `record`\n\t\t} else {\n\t\t\tresult = super.unshift(...items)\n\t\t}\n\t\treturn result\n\t}\n\n\tpublic reverse(): this {\n\t\tsuper.reverse()\n\t\tif (this.mode === `record`) {\n\t\t\tthis.emit({ type: `reverse` })\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic fill(value: P, start?: number, end?: number): this {\n\t\tif (this.mode === `record`) {\n\t\t\tthis.mode = `playback`\n\t\t\tconst prev = this.slice(start, end)\n\t\t\tsuper.fill(value, start, end)\n\t\t\tif (start === undefined) {\n\t\t\t\tthis.emit({ type: `fill`, value, prev })\n\t\t\t} else {\n\t\t\t\tif (end === undefined) {\n\t\t\t\t\tthis.emit({ type: `fill`, value, start, prev })\n\t\t\t\t} else {\n\t\t\t\t\tthis.emit({ type: `fill`, value, start, end, prev })\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.mode = `record`\n\t\t} else {\n\t\t\tsuper.fill(value, start, end)\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic sort(compareFn?: (a: P, b: P) => number): this {\n\t\tif (this.mode === `record`) {\n\t\t\tthis.mode = `playback`\n\t\t\tconst prev = [...this]\n\t\t\tsuper.sort(compareFn)\n\t\t\tconst next = [...this]\n\t\t\tthis.emit({ type: `sort`, next, prev })\n\t\t\tthis.mode = `record`\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic splice(start: number, deleteCount?: number): P[]\n\tpublic splice(start: number, deleteCount: number, ...items: P[]): P[]\n\tpublic splice(\n\t\t...params: [start: number, deleteCount?: number, ...items: P[]]\n\t): P[] {\n\t\tconst [start, deleteCount, ...items] = params\n\t\tconst originalMode = this.mode\n\t\tif (originalMode === `record`) this.mode = `playback`\n\t\tconst deleted = super.splice(...(params as [number, number, ...P[]]))\n\t\tif (originalMode === `record`) this.mode = `record`\n\t\tif (deleteCount === undefined) {\n\t\t\tthis.emit({\n\t\t\t\ttype: `splice`,\n\t\t\t\tstart,\n\t\t\t\titems,\n\t\t\t\tdeleted,\n\t\t\t\tdeleteCount: deleted.length,\n\t\t\t})\n\t\t} else {\n\t\t\tthis.emit({ type: `splice`, start, items, deleted, deleteCount })\n\t\t}\n\n\t\treturn deleted\n\t}\n\n\tpublic copyWithin(target: number, start: number, end?: number): this {\n\t\tconst originalMode = this.mode\n\t\tlet prev: P[] | undefined\n\t\tif (originalMode === `record`) {\n\t\t\tprev = this.slice(target)\n\t\t\tthis.mode = `playback`\n\t\t}\n\t\tsuper.copyWithin(target, start, end)\n\t\tif (originalMode === `record`) this.mode = `record`\n\t\tif (prev) {\n\t\t\tif (end === undefined) {\n\t\t\t\tthis.emit({ type: `copyWithin`, prev, target, start })\n\t\t\t} else {\n\t\t\t\tthis.emit({ type: `copyWithin`, prev, target, start, end })\n\t\t\t}\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic subscribe(\n\t\tkey: string,\n\t\tfn: (update: PackedArrayUpdate<P>) => void,\n\t): () => void {\n\t\treturn this.subject.subscribe(key, fn)\n\t}\n\n\tpublic emit(update: ArrayUpdate<P>): void {\n\t\tthis.subject.next(OList.packUpdate(update))\n\t}\n\n\tprivate doStep(update: ArrayUpdate<P>): void {\n\t\tconst type = update.type\n\t\tswitch (type) {\n\t\t\tcase `copyWithin`:\n\t\t\t\tthis.copyWithin(update.target, update.start, update.end)\n\t\t\t\tbreak\n\t\t\tcase `extend`:\n\t\t\t\tthis.length = update.next\n\t\t\t\tbreak\n\t\t\tcase `fill`:\n\t\t\t\tthis.fill(update.value, update.start, update.end)\n\t\t\t\tbreak\n\t\t\tcase `pop`:\n\t\t\t\tthis.pop()\n\t\t\t\tbreak\n\t\t\tcase `push`:\n\t\t\t\tthis.push(...update.items)\n\t\t\t\tbreak\n\t\t\tcase `reverse`:\n\t\t\t\tthis.reverse()\n\t\t\t\tbreak\n\t\t\tcase `shift`:\n\t\t\t\tthis.shift()\n\t\t\t\tbreak\n\t\t\tcase `sort`:\n\t\t\t\tfor (let i = 0; i < update.next.length; i++) {\n\t\t\t\t\tthis[i] = update.next[i]\n\t\t\t\t}\n\t\t\t\tthis.length = update.next.length\n\t\t\t\tbreak\n\t\t\tcase `splice`:\n\t\t\t\tthis.splice(update.start, update.deleteCount, ...update.items)\n\t\t\t\tbreak\n\t\t\tcase `truncate`:\n\t\t\t\tthis.length = update.length\n\t\t\t\tbreak\n\t\t\tcase `set`:\n\t\t\t\tthis[update.index] = update.next\n\t\t\t\tbreak\n\t\t\tcase `unshift`:\n\t\t\t\tthis.unshift(...update.items)\n\t\t\t\tbreak\n\t\t}\n\t}\n\n\tpublic do(update: PackedArrayUpdate<P>): null {\n\t\tthis.mode = `playback`\n\t\tconst unpacked = OList.unpackUpdate(update)\n\t\tthis.doStep(unpacked)\n\t\tthis.mode = `record`\n\t\treturn null\n\t}\n\n\tpublic undoStep(update: ArrayUpdate<P>): void {\n\t\tswitch (update.type) {\n\t\t\tcase `copyWithin`:\n\t\t\t\tfor (let i = 0; i < update.prev.length; i++) {\n\t\t\t\t\tthis[i + update.target] = update.prev[i]\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase `extend`:\n\t\t\t\tthis.length = update.prev\n\t\t\t\tbreak\n\t\t\tcase `fill`:\n\t\t\t\t{\n\t\t\t\t\tconst start = update.start ?? 0\n\t\t\t\t\tfor (let i = 0; i < update.prev.length; i++) {\n\t\t\t\t\t\tthis[i + start] = update.prev[i]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase `pop`:\n\t\t\t\tif (update.value) this.push(update.value)\n\t\t\t\tbreak\n\t\t\tcase `push`:\n\t\t\t\t{\n\t\t\t\t\tlet i = update.items.length - 1\n\t\t\t\t\twhile (i >= 0) {\n\t\t\t\t\t\tthis.pop()\n\t\t\t\t\t\t--i\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase `reverse`:\n\t\t\t\tthis.reverse()\n\t\t\t\tbreak\n\t\t\tcase `shift`:\n\t\t\t\tif (update.value) this.unshift(update.value)\n\t\t\t\tbreak\n\t\t\tcase `sort`:\n\t\t\t\tfor (let i = 0; i < update.prev.length; i++) {\n\t\t\t\t\tthis[i] = update.prev[i]\n\t\t\t\t}\n\t\t\t\tthis.length = update.prev.length\n\t\t\t\tbreak\n\t\t\tcase `set`:\n\t\t\t\tif (update.prev) {\n\t\t\t\t\tthis[update.index] = update.prev\n\t\t\t\t} else {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\t\t\tdelete this[update.index]\n\t\t\t\t\tconst firstEmptyIndex = this.findIndex(\n\t\t\t\t\t\t(_, i) => !Object.hasOwn(this, i),\n\t\t\t\t\t)\n\t\t\t\t\tif (firstEmptyIndex !== -1) {\n\t\t\t\t\t\tthis.length = firstEmptyIndex\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase `splice`:\n\t\t\t\tthis.splice(update.start, update.items.length, ...update.deleted)\n\t\t\t\tbreak\n\t\t\tcase `truncate`:\n\t\t\t\tthis.push(...update.items)\n\t\t\t\tbreak\n\t\t\tcase `unshift`:\n\t\t\t\t{\n\t\t\t\t\tlet i = update.items.length - 1\n\t\t\t\t\twhile (i >= 0) {\n\t\t\t\t\t\tthis.shift()\n\t\t\t\t\t\t--i\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t}\n\t}\n\n\tpublic undo(update: PackedArrayUpdate<P>): number | null {\n\t\tthis.mode = `playback`\n\t\tconst unpacked = OList.unpackUpdate(update)\n\t\tthis.undoStep(unpacked)\n\t\tthis.mode = `record`\n\t\treturn null\n\t}\n\n\tpublic static packUpdate<P extends primitive>(\n\t\tupdate: ArrayUpdate<P>,\n\t): PackedArrayUpdate<P> {\n\t\tlet packed = ARRAY_UPDATE_ENUM[update.type] + `\\u001F`\n\t\tswitch (update.type) {\n\t\t\tcase `set`:\n\t\t\t\tpacked += update.index + `\\u001E` + packValue(update.next)\n\t\t\t\tif (update.prev !== undefined) {\n\t\t\t\t\tpacked += `\\u001E` + packValue(update.prev)\n\t\t\t\t}\n\t\t\t\treturn packed\n\t\t\tcase `truncate`:\n\t\t\t\treturn (\n\t\t\t\t\tpacked +\n\t\t\t\t\tupdate.length +\n\t\t\t\t\t`\\u001E` +\n\t\t\t\t\tupdate.items.map(packValue).join(`\\u001E`)\n\t\t\t\t)\n\t\t\tcase `extend`:\n\t\t\t\treturn packed + update.next + `\\u001E` + update.prev\n\t\t\tcase `pop`:\n\t\t\tcase `shift`:\n\t\t\t\tif (update.value !== undefined) {\n\t\t\t\t\tpacked += packValue(update.value)\n\t\t\t\t}\n\t\t\t\treturn packed\n\t\t\tcase `push`:\n\t\t\tcase `unshift`:\n\t\t\t\treturn packed + update.items.map(packValue).join(`\\u001E`)\n\t\t\tcase `copyWithin`:\n\t\t\t\tpacked += update.target + `\\u001E` + update.start\n\t\t\t\tif (update.end !== undefined) {\n\t\t\t\t\tpacked += `\\u001E` + update.end\n\t\t\t\t}\n\t\t\t\tpacked += `\\u001E\\u001E` + update.prev.map(packValue).join(`\\u001E`)\n\t\t\t\treturn packed\n\t\t\tcase `fill`:\n\t\t\t\tpacked += packValue(update.value)\n\t\t\t\tif (update.start !== undefined) {\n\t\t\t\t\tpacked += `\\u001E` + update.start\n\t\t\t\t}\n\t\t\t\tif (update.end !== undefined) {\n\t\t\t\t\tpacked += `\\u001E` + update.end\n\t\t\t\t}\n\t\t\t\tpacked += `\\u001E\\u001E` + update.prev.map(packValue).join(`\\u001E`)\n\t\t\t\treturn packed\n\t\t\tcase `splice`:\n\t\t\t\treturn (\n\t\t\t\t\tpacked +\n\t\t\t\t\tupdate.start +\n\t\t\t\t\t`\\u001E\\u001E` +\n\t\t\t\t\tupdate.deleteCount +\n\t\t\t\t\t`\\u001E\\u001E` +\n\t\t\t\t\tupdate.items.map(packValue).join(`\\u001E`) +\n\t\t\t\t\t`\\u001E\\u001E` +\n\t\t\t\t\tupdate.deleted.map(packValue).join(`\\u001E`)\n\t\t\t\t)\n\t\t\tcase `reverse`:\n\t\t\t\treturn packed\n\t\t\tcase `sort`:\n\t\t\t\treturn (\n\t\t\t\t\tpacked +\n\t\t\t\t\tupdate.next.map(packValue).join(`\\u001E`) +\n\t\t\t\t\t`\\u001E\\u001E` +\n\t\t\t\t\tupdate.prev.map(packValue).join(`\\u001E`)\n\t\t\t\t)\n\t\t}\n\t}\n\n\tpublic static unpackUpdate<P extends primitive>(\n\t\tpacked: PackedArrayUpdate<P>,\n\t): ArrayUpdate<P> {\n\t\tconst [head, tail] = packed.split(`\\u001F`) as [\n\t\t\tExtract<keyof typeof ARRAY_UPDATE_ENUM, number>,\n\t\t\tstring,\n\t\t]\n\t\tconst type = ARRAY_UPDATE_ENUM[head]\n\t\tswitch (type) {\n\t\t\tcase `set`: {\n\t\t\t\tconst [i, n, p] = tail.split(`\\u001E`)\n\t\t\t\tconst index = +i\n\t\t\t\tconst next = unpackValue(n) as P\n\t\t\t\tif (p === undefined) {\n\t\t\t\t\treturn { type, index, next }\n\t\t\t\t}\n\t\t\t\tconst prev = unpackValue(p) as P\n\t\t\t\treturn { type, index, next, prev }\n\t\t\t}\n\t\t\tcase `truncate`: {\n\t\t\t\tconst [l, ...i] = tail.split(`\\u001E`)\n\t\t\t\tconst length = +l\n\t\t\t\tconst items = i.map(unpackValue) as P[]\n\t\t\t\treturn { type, length, items }\n\t\t\t}\n\t\t\tcase `extend`: {\n\t\t\t\tconst [n, p] = tail.split(`\\u001E`)\n\t\t\t\tconst next = +n\n\t\t\t\tconst prev = +p\n\t\t\t\treturn { type, next, prev }\n\t\t\t}\n\t\t\tcase `pop`:\n\t\t\tcase `shift`:\n\t\t\t\tif (tail !== ``) {\n\t\t\t\t\tconst value = unpackValue(tail) as P\n\t\t\t\t\treturn { type, value }\n\t\t\t\t}\n\t\t\t\treturn { type }\n\t\t\tcase `push`:\n\t\t\tcase `unshift`: {\n\t\t\t\tconst items = tail.split(`\\u001E`).map(unpackValue) as P[]\n\t\t\t\treturn { type, items }\n\t\t\t}\n\t\t\tcase `copyWithin`: {\n\t\t\t\tconst [numbers, data] = tail.split(`\\u001E\\u001E`)\n\t\t\t\tconst prev = data ? (data.split(`\\u001E`).map(unpackValue) as P[]) : []\n\t\t\t\tconst [t, s, e] = numbers.split(`\\u001E`)\n\t\t\t\tconst target = +t\n\t\t\t\tconst start = +s\n\t\t\t\tif (e === undefined) {\n\t\t\t\t\treturn { type, target, start, prev }\n\t\t\t\t}\n\t\t\t\tconst end = +e\n\t\t\t\treturn { type, target, start, prev, end }\n\t\t\t}\n\t\t\tcase `fill`: {\n\t\t\t\tconst [numbers, data] = tail.split(`\\u001E\\u001E`)\n\t\t\t\tconst prev = data ? (data.split(`\\u001E`).map(unpackValue) as P[]) : []\n\t\t\t\tconst [v, s, e] = numbers.split(`\\u001E`)\n\t\t\t\tconst value = unpackValue(v) as P\n\t\t\t\tif (s === undefined && e === undefined) {\n\t\t\t\t\treturn { type, value, prev }\n\t\t\t\t}\n\t\t\t\tconst start = +s\n\t\t\t\tif (e === undefined) {\n\t\t\t\t\treturn { type, value, prev, start }\n\t\t\t\t}\n\t\t\t\tconst end = +e\n\t\t\t\treturn { type, value, prev, start, end }\n\t\t\t}\n\t\t\tcase `splice`: {\n\t\t\t\tconst [s, c, i, d] = tail.split(`\\u001E\\u001E`)\n\n\t\t\t\tconst start = +s\n\t\t\t\tconst deleteCount = +c\n\t\t\t\tconst items = i ? (i.split(`\\u001E`).map(unpackValue) as P[]) : []\n\t\t\t\tconst deleted = d ? (d.split(`\\u001E`).map(unpackValue) as P[]) : []\n\t\t\t\treturn { type, start, deleteCount, items, deleted }\n\t\t\t}\n\t\t\tcase `reverse`:\n\t\t\t\treturn { type }\n\t\t\tcase `sort`: {\n\t\t\t\tconst [n, p] = tail.split(`\\u001E\\u001E`)\n\t\t\t\tconst next = n ? (n.split(`\\u001E`).map(unpackValue) as P[]) : []\n\t\t\t\tconst prev = p ? (p.split(`\\u001E`).map(unpackValue) as P[]) : []\n\t\t\t\treturn { type, next, prev }\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":";;;;AAuEA,MAAM,gBAAgB;CAErB;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAKD,MAAaA,oBACZ,YAAY,cAAc;AAa3B,IAAa,QAAb,MAAa,cACJ,MAIT;CACC,AAAO,OAAwB;CAC/B,AAAgB,UAAyC,IAAI,SAAS;CAEtE,AAAgB,gBAA8B;CAI9C,AAAO,YAAY,GAAG,OAAY;AACjC,QAAM,GAAG,MAAM;AAEf,SAAO,IAAI,MAAM,MAAM,EACtB,MAAM,QAAQ,MAAM,OAAO,aAAa;AACvC,OACC,OAAO,SAAS,YAChB,CAAC,OAAO,MAAM,OAAO,SAAS,MAAM,GAAG,CAAC,EACvC;IACD,MAAM,QAAQ,OAAO,KAAK;IAC1B,IAAIC;AACJ,QAAI,KAAK,SAAS,SACjB,QAAO,OAAO;AAEf,WAAO,SAAS;AAChB,QAAI,KACH,MAAK,KAAK;KAAE,MAAM;KAAO;KAAO,MAAM;KAAO;KAAM,CAAC;aAC1C,KAAK,SAAS,SACxB,MAAK,KAAK;KAAE,MAAM;KAAO;KAAO,MAAM;KAAO,CAAC;AAE/C,WAAO;;AAER,OAAI,SAAS,UAAU;AACtB,QAAI,KAAK,SAAS,UAAU;KAC3B,MAAM,aAAa,OAAO;AAC1B,SAAI,eAAe,MAAO,QAAO;AACjC,SAAI,aAAa,OAAO;MACvB,MAAM,UAAU,OAAO,MAAM,MAAM;AACnC,aAAO,SAA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Q,IAAK,EAAE,MAAM,SAAS,CAAC,IAAI,YAAY,GAAW,EAAE;IAClE,MAAM,UAAU,IAAK,EAAE,MAAM,SAAS,CAAC,IAAI,YAAY,GAAW,EAAE;AACpE,WAAO;KAAE;KAAM;KAAO;KAAa;KAAO;KAAS;;GAEpD,KAAK,UACJ,QAAO,EAAE,MAAM;GAChB,KAAK,QAAQ;IACZ,MAAM,CAAC,GAAG,KAAK,KAAK,MAAM,eAAe;IACzC,MAAM,OAAO,IAAK,EAAE,MAAM,SAAS,CAAC,IAAI,YAAY,GAAW,EAAE;IACjE,MAAM,OAAO,IAAK,EAAE,MAAM,SAAS,CAAC,IAAI,YAAY,GAAW,EAAE;AACjE,WAAO;KAAE;KAAM;KAAM;KAAM"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["ARRAY_UPDATE_ENUM: Enumeration<typeof ARRAY_UPDATES>","prev: P | undefined","result: number","value: P | undefined","prev: P[] | undefined","oListDisposedKeyCleanupEffect: AtomEffect<OList<primitive>>"],"sources":["../../../src/transceivers/o-list/o-list.ts","../../../src/transceivers/o-list/o-list-disposed-key-cleanup-effect.ts"],"sourcesContent":["import type { Fn, Transceiver, TransceiverMode } from \"atom.io/internal\"\nimport { Subject } from \"atom.io/internal\"\nimport type { primitive } from \"atom.io/json\"\nimport type { Enumeration } from \"atom.io/struct\"\nimport { enumeration, packValue, unpackValue } from \"atom.io/struct\"\n\nexport type ArrayMutations = Exclude<keyof Array<any>, keyof ReadonlyArray<any>>\nexport type ArrayUpdate<P extends primitive> =\n\t| {\n\t\t\ttype: `copyWithin`\n\t\t\ttarget: number\n\t\t\tstart: number\n\t\t\tend?: number\n\t\t\tprev: readonly P[]\n\t }\n\t| {\n\t\t\ttype: `extend`\n\t\t\tnext: number\n\t\t\tprev: number\n\t }\n\t| {\n\t\t\ttype: `fill`\n\t\t\tvalue: P\n\t\t\tstart?: number\n\t\t\tend?: number\n\t\t\tprev: readonly P[]\n\t }\n\t| {\n\t\t\ttype: `pop` | `shift`\n\t\t\tvalue?: P\n\t }\n\t| {\n\t\t\ttype: `push` | `unshift`\n\t\t\titems: readonly P[]\n\t }\n\t| {\n\t\t\ttype: `reverse`\n\t }\n\t| {\n\t\t\ttype: `set`\n\t\t\tnext: P\n\t\t\tprev?: P\n\t\t\tindex: number\n\t }\n\t| {\n\t\t\ttype: `sort`\n\t\t\tnext: readonly P[]\n\t\t\tprev: readonly P[]\n\t }\n\t| {\n\t\t\ttype: `splice`\n\t\t\tstart: number\n\t\t\tdeleteCount: number\n\t\t\titems: readonly P[]\n\t\t\tdeleted: readonly P[]\n\t }\n\t| {\n\t\t\ttype: `truncate`\n\t\t\tlength: number\n\t\t\titems: readonly P[]\n\t }\nexport type OListUpdateType = ArrayUpdate<any>[`type`]\ntrue satisfies ArrayMutations extends OListUpdateType\n\t? true\n\t: Exclude<ArrayMutations, OListUpdateType>\n\nexport type PackedArrayUpdate<P extends primitive> = string & {\n\tupdate?: ArrayUpdate<P>\n\ttype?: P\n}\n\nconst ARRAY_UPDATES = [\n\t// virtual methods\n\t`set`,\n\t`truncate`,\n\t`extend`,\n\t// actual methods\n\t`pop`,\n\t`push`,\n\t`shift`,\n\t`unshift`,\n\t`copyWithin`,\n\t`fill`,\n\t`splice`,\n\t`reverse`,\n\t`sort`,\n] as const\ntrue satisfies ArrayUpdate<any>[`type`] extends (typeof ARRAY_UPDATES)[number]\n\t? true\n\t: Exclude<ArrayUpdate<any>[`type`], (typeof ARRAY_UPDATES)[number]>\n\nexport const ARRAY_UPDATE_ENUM: Enumeration<typeof ARRAY_UPDATES> =\n\tenumeration(ARRAY_UPDATES)\n\nexport type ArrayMutationHandler = {\n\t[K in Exclude<OListUpdateType, `extend` | `set` | `truncate`>]: Fn\n}\n\nexport type OListView<P extends primitive> = ReadonlyArray<P> & {\n\tsubscribe: (\n\t\tkey: string,\n\t\tfn: (update: PackedArrayUpdate<P>) => void,\n\t) => () => void\n}\n\nexport class OList<P extends primitive>\n\textends Array<P>\n\timplements\n\t\tTransceiver<OListView<P>, PackedArrayUpdate<P>, ReadonlyArray<P>>,\n\t\tArrayMutationHandler\n{\n\tpublic mode: TransceiverMode = `record`\n\tpublic readonly subject: Subject<PackedArrayUpdate<P>> = new Subject()\n\n\tpublic readonly READONLY_VIEW: OListView<P> = this\n\n\tpublic constructor(arrayLength?: number)\n\tpublic constructor(...items: P[])\n\tpublic constructor(...items: P[]) {\n\t\tsuper(...items)\n\t\t// biome-ignore lint/correctness/noConstructorReturn: this is chill\n\t\treturn new Proxy(this, {\n\t\t\tset: (target, prop, value, receiver) => {\n\t\t\t\tif (\n\t\t\t\t\ttypeof prop === `string` &&\n\t\t\t\t\t!Number.isNaN(Number.parseInt(prop, 10))\n\t\t\t\t) {\n\t\t\t\t\tconst index = Number(prop)\n\t\t\t\t\tlet prev: P | undefined\n\t\t\t\t\tif (this.mode === `record`) {\n\t\t\t\t\t\tprev = target[index]\n\t\t\t\t\t}\n\t\t\t\t\ttarget[index] = value\n\t\t\t\t\tif (prev) {\n\t\t\t\t\t\tthis.emit({ type: `set`, index, next: value, prev })\n\t\t\t\t\t} else if (this.mode === `record`) {\n\t\t\t\t\t\tthis.emit({ type: `set`, index, next: value })\n\t\t\t\t\t}\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\tif (prop === `length`) {\n\t\t\t\t\tif (this.mode === `record`) {\n\t\t\t\t\t\tconst prevLength = target.length\n\t\t\t\t\t\tif (prevLength === value) return true\n\t\t\t\t\t\tif (prevLength > value) {\n\t\t\t\t\t\t\tconst dropped = target.slice(value)\n\t\t\t\t\t\t\ttarget.length = value\n\t\t\t\t\t\t\tthis.emit({ type: `truncate`, length: value, items: dropped })\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\ttarget.length = value\n\t\t\t\t\t\t\tthis.emit({ type: `extend`, next: value, prev: prevLength })\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttarget.length = value\n\t\t\t\t\t}\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\treturn Reflect.set(target, prop, value, receiver)\n\t\t\t},\n\t\t})\n\t}\n\n\tpublic toJSON(): ReadonlyArray<P> {\n\t\treturn [...this]\n\t}\n\n\tpublic static fromJSON<P extends primitive>(json: ReadonlyArray<P>): OList<P> {\n\t\treturn new OList<P>(...json)\n\t}\n\n\tpublic push(...items: P[]): number {\n\t\tlet result: number\n\t\tif (this.mode === `record`) {\n\t\t\tthis.mode = `playback`\n\t\t\tresult = super.push(...items)\n\t\t\tthis.mode = `record`\n\t\t\tthis.emit({ type: `push`, items })\n\t\t} else {\n\t\t\tresult = super.push(...items)\n\t\t}\n\t\treturn result\n\t}\n\tpublic pop(): P | undefined {\n\t\tlet value: P | undefined\n\t\tif (this.mode === `record`) {\n\t\t\tthis.mode = `playback`\n\t\t\tvalue = super.pop()\n\t\t\tif (value === undefined) {\n\t\t\t\tthis.emit({ type: `pop` })\n\t\t\t} else {\n\t\t\t\tthis.emit({ type: `pop`, value })\n\t\t\t}\n\t\t\tthis.mode = `record`\n\t\t} else {\n\t\t\tvalue = super.pop()\n\t\t}\n\t\treturn value\n\t}\n\tpublic shift(): P | undefined {\n\t\tlet value: P | undefined\n\t\tif (this.mode === `record`) {\n\t\t\tthis.mode = `playback`\n\t\t\tvalue = super.shift()\n\t\t\tif (value === undefined) {\n\t\t\t\tthis.emit({ type: `shift` })\n\t\t\t} else {\n\t\t\t\tthis.emit({ type: `shift`, value })\n\t\t\t}\n\t\t\tthis.mode = `record`\n\t\t} else {\n\t\t\tvalue = super.shift()\n\t\t}\n\t\treturn value\n\t}\n\tpublic unshift(...items: P[]): number {\n\t\tlet result: number\n\t\tif (this.mode === `record`) {\n\t\t\tthis.mode = `playback`\n\t\t\tresult = super.unshift(...items)\n\t\t\tthis.emit({ type: `unshift`, items })\n\t\t\tthis.mode = `record`\n\t\t} else {\n\t\t\tresult = super.unshift(...items)\n\t\t}\n\t\treturn result\n\t}\n\n\tpublic reverse(): this {\n\t\tsuper.reverse()\n\t\tif (this.mode === `record`) {\n\t\t\tthis.emit({ type: `reverse` })\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic fill(value: P, start?: number, end?: number): this {\n\t\tif (this.mode === `record`) {\n\t\t\tthis.mode = `playback`\n\t\t\tconst prev = this.slice(start, end)\n\t\t\tsuper.fill(value, start, end)\n\t\t\tif (start === undefined) {\n\t\t\t\tthis.emit({ type: `fill`, value, prev })\n\t\t\t} else {\n\t\t\t\tif (end === undefined) {\n\t\t\t\t\tthis.emit({ type: `fill`, value, start, prev })\n\t\t\t\t} else {\n\t\t\t\t\tthis.emit({ type: `fill`, value, start, end, prev })\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.mode = `record`\n\t\t} else {\n\t\t\tsuper.fill(value, start, end)\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic sort(compareFn?: (a: P, b: P) => number): this {\n\t\tif (this.mode === `record`) {\n\t\t\tthis.mode = `playback`\n\t\t\tconst prev = [...this]\n\t\t\tsuper.sort(compareFn)\n\t\t\tconst next = [...this]\n\t\t\tthis.emit({ type: `sort`, next, prev })\n\t\t\tthis.mode = `record`\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic splice(start: number, deleteCount?: number): P[]\n\tpublic splice(start: number, deleteCount: number, ...items: P[]): P[]\n\tpublic splice(\n\t\t...params: [start: number, deleteCount?: number, ...items: P[]]\n\t): P[] {\n\t\tconst [start, deleteCount, ...items] = params\n\t\tconst originalMode = this.mode\n\t\tif (originalMode === `record`) this.mode = `playback`\n\t\tconst deleted = super.splice(...(params as [number, number, ...P[]]))\n\t\tif (originalMode === `record`) this.mode = `record`\n\t\tif (deleteCount === undefined) {\n\t\t\tthis.emit({\n\t\t\t\ttype: `splice`,\n\t\t\t\tstart,\n\t\t\t\titems,\n\t\t\t\tdeleted,\n\t\t\t\tdeleteCount: deleted.length,\n\t\t\t})\n\t\t} else {\n\t\t\tthis.emit({ type: `splice`, start, items, deleted, deleteCount })\n\t\t}\n\n\t\treturn deleted\n\t}\n\n\tpublic copyWithin(target: number, start: number, end?: number): this {\n\t\tconst originalMode = this.mode\n\t\tlet prev: P[] | undefined\n\t\tif (originalMode === `record`) {\n\t\t\tprev = this.slice(target)\n\t\t\tthis.mode = `playback`\n\t\t}\n\t\tsuper.copyWithin(target, start, end)\n\t\tif (originalMode === `record`) this.mode = `record`\n\t\tif (prev) {\n\t\t\tif (end === undefined) {\n\t\t\t\tthis.emit({ type: `copyWithin`, prev, target, start })\n\t\t\t} else {\n\t\t\t\tthis.emit({ type: `copyWithin`, prev, target, start, end })\n\t\t\t}\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic subscribe(\n\t\tkey: string,\n\t\tfn: (update: PackedArrayUpdate<P>) => void,\n\t): () => void {\n\t\treturn this.subject.subscribe(key, fn)\n\t}\n\n\tpublic emit(update: ArrayUpdate<P>): void {\n\t\tthis.subject.next(OList.packUpdate(update))\n\t}\n\n\tprivate doStep(update: ArrayUpdate<P>): void {\n\t\tconst type = update.type\n\t\tswitch (type) {\n\t\t\tcase `copyWithin`:\n\t\t\t\tthis.copyWithin(update.target, update.start, update.end)\n\t\t\t\tbreak\n\t\t\tcase `extend`:\n\t\t\t\tthis.length = update.next\n\t\t\t\tbreak\n\t\t\tcase `fill`:\n\t\t\t\tthis.fill(update.value, update.start, update.end)\n\t\t\t\tbreak\n\t\t\tcase `pop`:\n\t\t\t\tthis.pop()\n\t\t\t\tbreak\n\t\t\tcase `push`:\n\t\t\t\tthis.push(...update.items)\n\t\t\t\tbreak\n\t\t\tcase `reverse`:\n\t\t\t\tthis.reverse()\n\t\t\t\tbreak\n\t\t\tcase `shift`:\n\t\t\t\tthis.shift()\n\t\t\t\tbreak\n\t\t\tcase `sort`:\n\t\t\t\tfor (let i = 0; i < update.next.length; i++) {\n\t\t\t\t\tthis[i] = update.next[i]\n\t\t\t\t}\n\t\t\t\tthis.length = update.next.length\n\t\t\t\tbreak\n\t\t\tcase `splice`:\n\t\t\t\tthis.splice(update.start, update.deleteCount, ...update.items)\n\t\t\t\tbreak\n\t\t\tcase `truncate`:\n\t\t\t\tthis.length = update.length\n\t\t\t\tbreak\n\t\t\tcase `set`:\n\t\t\t\tthis[update.index] = update.next\n\t\t\t\tbreak\n\t\t\tcase `unshift`:\n\t\t\t\tthis.unshift(...update.items)\n\t\t\t\tbreak\n\t\t}\n\t}\n\n\tpublic do(update: PackedArrayUpdate<P>): null {\n\t\tthis.mode = `playback`\n\t\tconst unpacked = OList.unpackUpdate(update)\n\t\tthis.doStep(unpacked)\n\t\tthis.mode = `record`\n\t\treturn null\n\t}\n\n\tpublic undoStep(update: ArrayUpdate<P>): void {\n\t\tswitch (update.type) {\n\t\t\tcase `copyWithin`:\n\t\t\t\tfor (let i = 0; i < update.prev.length; i++) {\n\t\t\t\t\tthis[i + update.target] = update.prev[i]\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase `extend`:\n\t\t\t\tthis.length = update.prev\n\t\t\t\tbreak\n\t\t\tcase `fill`:\n\t\t\t\t{\n\t\t\t\t\tconst start = update.start ?? 0\n\t\t\t\t\tfor (let i = 0; i < update.prev.length; i++) {\n\t\t\t\t\t\tthis[i + start] = update.prev[i]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase `pop`:\n\t\t\t\tif (update.value) this.push(update.value)\n\t\t\t\tbreak\n\t\t\tcase `push`:\n\t\t\t\t{\n\t\t\t\t\tlet i = update.items.length - 1\n\t\t\t\t\twhile (i >= 0) {\n\t\t\t\t\t\tthis.pop()\n\t\t\t\t\t\t--i\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase `reverse`:\n\t\t\t\tthis.reverse()\n\t\t\t\tbreak\n\t\t\tcase `shift`:\n\t\t\t\tif (update.value) this.unshift(update.value)\n\t\t\t\tbreak\n\t\t\tcase `sort`:\n\t\t\t\tfor (let i = 0; i < update.prev.length; i++) {\n\t\t\t\t\tthis[i] = update.prev[i]\n\t\t\t\t}\n\t\t\t\tthis.length = update.prev.length\n\t\t\t\tbreak\n\t\t\tcase `set`:\n\t\t\t\tif (update.prev) {\n\t\t\t\t\tthis[update.index] = update.prev\n\t\t\t\t} else {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\t\t\tdelete this[update.index]\n\t\t\t\t\tconst firstEmptyIndex = this.findIndex(\n\t\t\t\t\t\t(_, i) => !Object.hasOwn(this, i),\n\t\t\t\t\t)\n\t\t\t\t\tif (firstEmptyIndex !== -1) {\n\t\t\t\t\t\tthis.length = firstEmptyIndex\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\tcase `splice`:\n\t\t\t\tthis.splice(update.start, update.items.length, ...update.deleted)\n\t\t\t\tbreak\n\t\t\tcase `truncate`:\n\t\t\t\tthis.push(...update.items)\n\t\t\t\tbreak\n\t\t\tcase `unshift`:\n\t\t\t\t{\n\t\t\t\t\tlet i = update.items.length - 1\n\t\t\t\t\twhile (i >= 0) {\n\t\t\t\t\t\tthis.shift()\n\t\t\t\t\t\t--i\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t}\n\t}\n\n\tpublic undo(update: PackedArrayUpdate<P>): number | null {\n\t\tthis.mode = `playback`\n\t\tconst unpacked = OList.unpackUpdate(update)\n\t\tthis.undoStep(unpacked)\n\t\tthis.mode = `record`\n\t\treturn null\n\t}\n\n\tpublic static packUpdate<P extends primitive>(\n\t\tupdate: ArrayUpdate<P>,\n\t): PackedArrayUpdate<P> {\n\t\tlet packed = ARRAY_UPDATE_ENUM[update.type] + `\\u001F`\n\t\tswitch (update.type) {\n\t\t\tcase `set`:\n\t\t\t\tpacked += update.index + `\\u001E` + packValue(update.next)\n\t\t\t\tif (update.prev !== undefined) {\n\t\t\t\t\tpacked += `\\u001E` + packValue(update.prev)\n\t\t\t\t}\n\t\t\t\treturn packed\n\t\t\tcase `truncate`:\n\t\t\t\treturn (\n\t\t\t\t\tpacked +\n\t\t\t\t\tupdate.length +\n\t\t\t\t\t`\\u001E` +\n\t\t\t\t\tupdate.items.map(packValue).join(`\\u001E`)\n\t\t\t\t)\n\t\t\tcase `extend`:\n\t\t\t\treturn packed + update.next + `\\u001E` + update.prev\n\t\t\tcase `pop`:\n\t\t\tcase `shift`:\n\t\t\t\tif (update.value !== undefined) {\n\t\t\t\t\tpacked += packValue(update.value)\n\t\t\t\t}\n\t\t\t\treturn packed\n\t\t\tcase `push`:\n\t\t\tcase `unshift`:\n\t\t\t\treturn packed + update.items.map(packValue).join(`\\u001E`)\n\t\t\tcase `copyWithin`:\n\t\t\t\tpacked += update.target + `\\u001E` + update.start\n\t\t\t\tif (update.end !== undefined) {\n\t\t\t\t\tpacked += `\\u001E` + update.end\n\t\t\t\t}\n\t\t\t\tpacked += `\\u001E\\u001E` + update.prev.map(packValue).join(`\\u001E`)\n\t\t\t\treturn packed\n\t\t\tcase `fill`:\n\t\t\t\tpacked += packValue(update.value)\n\t\t\t\tif (update.start !== undefined) {\n\t\t\t\t\tpacked += `\\u001E` + update.start\n\t\t\t\t}\n\t\t\t\tif (update.end !== undefined) {\n\t\t\t\t\tpacked += `\\u001E` + update.end\n\t\t\t\t}\n\t\t\t\tpacked += `\\u001E\\u001E` + update.prev.map(packValue).join(`\\u001E`)\n\t\t\t\treturn packed\n\t\t\tcase `splice`:\n\t\t\t\treturn (\n\t\t\t\t\tpacked +\n\t\t\t\t\tupdate.start +\n\t\t\t\t\t`\\u001E\\u001E` +\n\t\t\t\t\tupdate.deleteCount +\n\t\t\t\t\t`\\u001E\\u001E` +\n\t\t\t\t\tupdate.items.map(packValue).join(`\\u001E`) +\n\t\t\t\t\t`\\u001E\\u001E` +\n\t\t\t\t\tupdate.deleted.map(packValue).join(`\\u001E`)\n\t\t\t\t)\n\t\t\tcase `reverse`:\n\t\t\t\treturn packed\n\t\t\tcase `sort`:\n\t\t\t\treturn (\n\t\t\t\t\tpacked +\n\t\t\t\t\tupdate.next.map(packValue).join(`\\u001E`) +\n\t\t\t\t\t`\\u001E\\u001E` +\n\t\t\t\t\tupdate.prev.map(packValue).join(`\\u001E`)\n\t\t\t\t)\n\t\t}\n\t}\n\n\tpublic static unpackUpdate<P extends primitive>(\n\t\tpacked: PackedArrayUpdate<P>,\n\t): ArrayUpdate<P> {\n\t\tconst [head, tail] = packed.split(`\\u001F`) as [\n\t\t\tExtract<keyof typeof ARRAY_UPDATE_ENUM, number>,\n\t\t\tstring,\n\t\t]\n\t\tconst type = ARRAY_UPDATE_ENUM[head]\n\t\tswitch (type) {\n\t\t\tcase `set`: {\n\t\t\t\tconst [i, n, p] = tail.split(`\\u001E`)\n\t\t\t\tconst index = +i\n\t\t\t\tconst next = unpackValue(n) as P\n\t\t\t\tif (p === undefined) {\n\t\t\t\t\treturn { type, index, next }\n\t\t\t\t}\n\t\t\t\tconst prev = unpackValue(p) as P\n\t\t\t\treturn { type, index, next, prev }\n\t\t\t}\n\t\t\tcase `truncate`: {\n\t\t\t\tconst [l, ...i] = tail.split(`\\u001E`)\n\t\t\t\tconst length = +l\n\t\t\t\tconst items = i.map(unpackValue) as P[]\n\t\t\t\treturn { type, length, items }\n\t\t\t}\n\t\t\tcase `extend`: {\n\t\t\t\tconst [n, p] = tail.split(`\\u001E`)\n\t\t\t\tconst next = +n\n\t\t\t\tconst prev = +p\n\t\t\t\treturn { type, next, prev }\n\t\t\t}\n\t\t\tcase `pop`:\n\t\t\tcase `shift`:\n\t\t\t\tif (tail !== ``) {\n\t\t\t\t\tconst value = unpackValue(tail) as P\n\t\t\t\t\treturn { type, value }\n\t\t\t\t}\n\t\t\t\treturn { type }\n\t\t\tcase `push`:\n\t\t\tcase `unshift`: {\n\t\t\t\tconst items = tail.split(`\\u001E`).map(unpackValue) as P[]\n\t\t\t\treturn { type, items }\n\t\t\t}\n\t\t\tcase `copyWithin`: {\n\t\t\t\tconst [numbers, data] = tail.split(`\\u001E\\u001E`)\n\t\t\t\tconst prev = data ? (data.split(`\\u001E`).map(unpackValue) as P[]) : []\n\t\t\t\tconst [t, s, e] = numbers.split(`\\u001E`)\n\t\t\t\tconst target = +t\n\t\t\t\tconst start = +s\n\t\t\t\tif (e === undefined) {\n\t\t\t\t\treturn { type, target, start, prev }\n\t\t\t\t}\n\t\t\t\tconst end = +e\n\t\t\t\treturn { type, target, start, prev, end }\n\t\t\t}\n\t\t\tcase `fill`: {\n\t\t\t\tconst [numbers, data] = tail.split(`\\u001E\\u001E`)\n\t\t\t\tconst prev = data ? (data.split(`\\u001E`).map(unpackValue) as P[]) : []\n\t\t\t\tconst [v, s, e] = numbers.split(`\\u001E`)\n\t\t\t\tconst value = unpackValue(v) as P\n\t\t\t\tif (s === undefined && e === undefined) {\n\t\t\t\t\treturn { type, value, prev }\n\t\t\t\t}\n\t\t\t\tconst start = +s\n\t\t\t\tif (e === undefined) {\n\t\t\t\t\treturn { type, value, prev, start }\n\t\t\t\t}\n\t\t\t\tconst end = +e\n\t\t\t\treturn { type, value, prev, start, end }\n\t\t\t}\n\t\t\tcase `splice`: {\n\t\t\t\tconst [s, c, i, d] = tail.split(`\\u001E\\u001E`)\n\n\t\t\t\tconst start = +s\n\t\t\t\tconst deleteCount = +c\n\t\t\t\tconst items = i ? (i.split(`\\u001E`).map(unpackValue) as P[]) : []\n\t\t\t\tconst deleted = d ? (d.split(`\\u001E`).map(unpackValue) as P[]) : []\n\t\t\t\treturn { type, start, deleteCount, items, deleted }\n\t\t\t}\n\t\t\tcase `reverse`:\n\t\t\t\treturn { type }\n\t\t\tcase `sort`: {\n\t\t\t\tconst [n, p] = tail.split(`\\u001E\\u001E`)\n\t\t\t\tconst next = n ? (n.split(`\\u001E`).map(unpackValue) as P[]) : []\n\t\t\t\tconst prev = p ? (p.split(`\\u001E`).map(unpackValue) as P[]) : []\n\t\t\t\treturn { type, next, prev }\n\t\t\t}\n\t\t}\n\t}\n}\n","import type { AtomEffect } from \"atom.io\"\nimport { getFromStore, getUpdateToken, subscribeInStore } from \"atom.io/internal\"\nimport { type primitive, stringifyJson } from \"atom.io/json\"\n\nimport { OList } from \"./o-list\"\n\nexport function filterOutInPlace<T>(arr: T[], toRemove: T): T[] {\n\tlet writeIndex = 0\n\n\t// eslint-disable-next-line @typescript-eslint/prefer-for-of\n\tfor (let readIndex = 0; readIndex < arr.length; readIndex++) {\n\t\tif (toRemove !== arr[readIndex]) {\n\t\t\tarr[writeIndex] = arr[readIndex]\n\t\t\twriteIndex++\n\t\t}\n\t}\n\n\tarr.length = writeIndex\n\treturn arr\n}\n\nexport const oListDisposedKeyCleanupEffect: AtomEffect<OList<primitive>> = ({\n\ttoken,\n\tsetSelf,\n\tstore,\n}) => {\n\tconst disposalSubscriptions = new Map<primitive, () => void>()\n\tconst updateToken = getUpdateToken(token)\n\n\tconst addedValues = new Set<primitive>()\n\tconst removedValues = new Set<primitive>()\n\tfunction updateSubscriptions() {\n\t\tfor (const addedValue of addedValues) {\n\t\t\tconst molecule = store.molecules.get(stringifyJson(addedValue))\n\t\t\tif (molecule) {\n\t\t\t\tdisposalSubscriptions.set(\n\t\t\t\t\taddedValue,\n\t\t\t\t\tmolecule.subject.subscribe(token.key, () => {\n\t\t\t\t\t\tdisposalSubscriptions.get(addedValue)?.()\n\t\t\t\t\t\tdisposalSubscriptions.delete(addedValue)\n\t\t\t\t\t\tsetSelf((self) => {\n\t\t\t\t\t\t\tfilterOutInPlace(self, addedValue)\n\t\t\t\t\t\t\treturn self\n\t\t\t\t\t\t})\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tstore.logger.warn(\n\t\t\t\t\t`❌`,\n\t\t\t\t\ttoken.type,\n\t\t\t\t\ttoken.key,\n\t\t\t\t\t`Added \"${addedValue}\" to ${token.key} but it has not been allocated.`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\tfor (const removedValue of removedValues) {\n\t\t\tif (disposalSubscriptions.has(removedValue)) {\n\t\t\t\tdisposalSubscriptions.get(removedValue)?.()\n\t\t\t\tdisposalSubscriptions.delete(removedValue)\n\t\t\t}\n\t\t}\n\t}\n\tsubscribeInStore(\n\t\tstore,\n\t\tupdateToken,\n\t\tfunction manageAutoDeletionTriggers({ newValue }) {\n\t\t\tconst currentList = getFromStore(store, token)\n\t\t\tconst unpacked = OList.unpackUpdate(newValue)\n\t\t\tswitch (unpacked.type) {\n\t\t\t\tcase `extend`:\n\t\t\t\tcase `reverse`:\n\t\t\t\tcase `sort`:\n\t\t\t\t\tbreak // these don't change what values are present in the list\n\n\t\t\t\tcase `set`:\n\t\t\t\t\t{\n\t\t\t\t\t\tconst { next } = unpacked\n\t\t\t\t\t\tif (`prev` in unpacked && !currentList.includes(unpacked.prev)) {\n\t\t\t\t\t\t\tremovedValues.add(unpacked.prev)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!disposalSubscriptions.has(next)) {\n\t\t\t\t\t\t\taddedValues.add(next)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\tcase `truncate`:\n\t\t\t\t\t{\n\t\t\t\t\t\tfor (const item of unpacked.items) {\n\t\t\t\t\t\t\tif (!currentList.includes(item)) {\n\t\t\t\t\t\t\t\tremovedValues.add(item)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\tcase `shift`:\n\t\t\t\tcase `pop`:\n\t\t\t\t\t{\n\t\t\t\t\t\tconst { value } = unpacked\n\t\t\t\t\t\tif (value !== undefined && !currentList.includes(value)) {\n\t\t\t\t\t\t\tremovedValues.add(value)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\tcase `push`:\n\t\t\t\tcase `unshift`:\n\t\t\t\t\tfor (const item of unpacked.items) {\n\t\t\t\t\t\tif (!disposalSubscriptions.has(item)) {\n\t\t\t\t\t\t\taddedValues.add(item)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\tcase `copyWithin`:\n\t\t\t\t\tfor (const item of unpacked.prev) {\n\t\t\t\t\t\tif (!currentList.includes(item)) {\n\t\t\t\t\t\t\tremovedValues.add(item)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\tcase `fill`:\n\t\t\t\t\t{\n\t\t\t\t\t\tconst { value } = unpacked\n\t\t\t\t\t\tif (value !== undefined) {\n\t\t\t\t\t\t\tif (!disposalSubscriptions.has(value)) {\n\t\t\t\t\t\t\t\taddedValues.add(value)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor (const item of unpacked.prev) {\n\t\t\t\t\t\t\tif (!currentList.includes(item)) {\n\t\t\t\t\t\t\t\tremovedValues.add(item)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\tcase `splice`:\n\t\t\t\t\tfor (const item of unpacked.deleted) {\n\t\t\t\t\t\tif (!currentList.includes(item)) {\n\t\t\t\t\t\t\tremovedValues.add(item)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (const addedItem of unpacked.items) {\n\t\t\t\t\t\tif (!disposalSubscriptions.has(addedItem)) {\n\t\t\t\t\t\t\taddedValues.add(addedItem)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t\tupdateSubscriptions()\n\t\t\taddedValues.clear()\n\t\t\tremovedValues.clear()\n\t\t},\n\t\t`set-auto-deletion-triggers`,\n\t)\n}\n"],"mappings":";;;;;AAuEA,MAAM,gBAAgB;CAErB;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAKD,MAAaA,oBACZ,YAAY,cAAc;AAa3B,IAAa,QAAb,MAAa,cACJ,MAIT;CACC,AAAO,OAAwB;CAC/B,AAAgB,UAAyC,IAAI,SAAS;CAEtE,AAAgB,gBAA8B;CAI9C,AAAO,YAAY,GAAG,OAA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SAAS,KAAK,CAC9B,eAAc,IAAI,KAAK;AAI1B;GACD,KAAK;GACL,KAAK;IACJ;KACC,MAAM,EAAE,UAAU;AAClB,SAAI,UAAU,UAAa,CAAC,YAAY,SAAS,MAAM,CACtD,eAAc,IAAI,MAAM;;AAG1B;GACD,KAAK;GACL,KAAK;AACJ,SAAK,MAAM,QAAQ,SAAS,MAC3B,KAAI,CAAC,sBAAsB,IAAI,KAAK,CACnC,aAAY,IAAI,KAAK;AAGvB;GACD,KAAK;AACJ,SAAK,MAAM,QAAQ,SAAS,KAC3B,KAAI,CAAC,YAAY,SAAS,KAAK,CAC9B,eAAc,IAAI,KAAK;AAGzB;GACD,KAAK;IACJ;KACC,MAAM,EAAE,UAAU;AAClB,SAAI,UAAU,QACb;UAAI,CAAC,sBAAsB,IAAI,MAAM,CACpC,aAAY,IAAI,MAAM;;AAGxB,UAAK,MAAM,QAAQ,SAAS,KAC3B,KAAI,CAAC,YAAY,SAAS,KAAK,CAC9B,eAAc,IAAI,KAAK;;AAI1B;GACD,KAAK;AACJ,SAAK,MAAM,QAAQ,SAAS,QAC3B,KAAI,CAAC,YAAY,SAAS,KAAK,CAC9B,eAAc,IAAI,KAAK;AAGzB,SAAK,MAAM,aAAa,SAAS,MAChC,KAAI,CAAC,sBAAsB,IAAI,UAAU,CACxC,aAAY,IAAI,UAAU;AAG5B;;AAEF,uBAAqB;AACrB,cAAY,OAAO;AACnB,gBAAc,OAAO;IAEtB,6BACA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Fn, Subject, Transceiver, TransceiverMode } from "atom.io/internal";
|
|
2
|
+
import { AtomEffect } from "atom.io";
|
|
2
3
|
import { primitive } from "atom.io/json";
|
|
3
4
|
import { Enumeration } from "atom.io/struct";
|
|
4
5
|
|
|
@@ -38,5 +39,8 @@ declare class UList<P extends primitive> extends Set<P> implements Transceiver<U
|
|
|
38
39
|
static unpackUpdate<P extends primitive>(packed: PackedSetUpdate<P>): SetUpdate<P>;
|
|
39
40
|
}
|
|
40
41
|
//#endregion
|
|
41
|
-
|
|
42
|
+
//#region src/transceivers/u-list/u-list-disposed-key-cleanup-effect.d.ts
|
|
43
|
+
declare const uListDisposedKeyCleanupEffect: AtomEffect<UList<primitive>>;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { PackedSetUpdate, SET_UPDATE_ENUM, SetMutationHandler, SetMutations, SetUpdate, UList, UListUpdateType, UListView, uListDisposedKeyCleanupEffect };
|
|
42
46
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["SET_UPDATE_ENUM: Enumeration<[`add`, `delete`, `clear`]>"],"sources":["../../../src/transceivers/u-list/u-list.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["SET_UPDATE_ENUM: Enumeration<[`add`, `delete`, `clear`]>","uListDisposedKeyCleanupEffect: AtomEffect<UList<primitive>>"],"sources":["../../../src/transceivers/u-list/u-list.ts","../../../src/transceivers/u-list/u-list-disposed-key-cleanup-effect.ts"],"sourcesContent":[],"mappings":";;;;;;KAMY,YAAA,GAAe,cACpB,yBACS;KAEJ,oBAAoB;EAJhC,IAAY,EAAA,KAAA,GAAA,QAAA;EAAA,KAAA,EAOF,CAPE;;QAEI,OAAA;QAFW,EAWhB,CAXgB,EAAA;CAAA;AAIf,KASA,eAAA,GAAkB,SATlB,CAAA,GAAA,CAAA,CAAA,MAAA,CAAA;AAAA,KAcA,eAdA,CAAA,UAc0B,SAd1B,CAAA,GAAA,MAAA,GAAA;QAAoB,CAAA,EAetB,SAfsB,CAeZ,CAfY,CAAA;;AAOrB,cAWEA,eAXF,EAWmB,WAXnB,CAAA,CAAA,KAAA,EAAA,QAAA,EAAA,OAAA,CAAA,CAAA;AAAA,KAcC,kBAAA,GAdD,QAc8B,eAd9B,GAcgD,EAdhD,EAAA;AAEC,KAcA,SAdA,CAAA,UAcoB,SAdF,CAAA,GAce,WAdf,CA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CAnEH,CAAA,CAAA,EAAA,IAAA;aAAyB,EAoFpC,eApFoC,CAoFpB,CApFoB,CAAA,CAAA,EAAA,MAAA,GAAA,IAAA;SAAZ,UAAA,CAAA,UAuGT,SAvGS,CAAA,CAAA,MAAA,EAwGnC,SAxGmC,CAwGzB,CAxGyB,CAAA,CAAA,EAyGzC,eAzGyC,CAyGzB,CAzGyB,CAAA;SAGd,YAAA,CAAA,UA6GO,SA7GP,CAAA,CAAA,MAAA,EA8GrB,eA9GqB,CA8GL,CA9GK,CAAA,CAAA,EA+G3B,SA/G2B,CA+GjB,CA/GiB,CAAA;;;;cC9BlBC,+BAA+B,WAAW,MAAM"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Subject } from "atom.io/internal";
|
|
1
|
+
import { Subject, getUpdateToken, subscribeInStore } from "atom.io/internal";
|
|
2
|
+
import { stringifyJson } from "atom.io/json";
|
|
2
3
|
import { enumeration, packValue, unpackValue } from "atom.io/struct";
|
|
3
4
|
|
|
4
5
|
//#region src/transceivers/u-list/u-list.ts
|
|
@@ -104,5 +105,35 @@ var UList = class UList extends Set {
|
|
|
104
105
|
};
|
|
105
106
|
|
|
106
107
|
//#endregion
|
|
107
|
-
|
|
108
|
+
//#region src/transceivers/u-list/u-list-disposed-key-cleanup-effect.ts
|
|
109
|
+
const uListDisposedKeyCleanupEffect = ({ token, setSelf, store }) => {
|
|
110
|
+
const disposalSubscriptions = /* @__PURE__ */ new Map();
|
|
111
|
+
const updateToken = getUpdateToken(token);
|
|
112
|
+
subscribeInStore(store, updateToken, function setAutoDeletionTriggers({ newValue }) {
|
|
113
|
+
const unpacked = UList.unpackUpdate(newValue);
|
|
114
|
+
switch (unpacked.type) {
|
|
115
|
+
case `add`:
|
|
116
|
+
{
|
|
117
|
+
const molecule = store.molecules.get(stringifyJson(unpacked.value));
|
|
118
|
+
if (molecule) disposalSubscriptions.set(unpacked.value, molecule.subject.subscribe(token.key, () => {
|
|
119
|
+
setSelf((self) => {
|
|
120
|
+
self.delete(unpacked.value);
|
|
121
|
+
return self;
|
|
122
|
+
});
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
case `delete`:
|
|
127
|
+
disposalSubscriptions.get(unpacked.value)?.();
|
|
128
|
+
disposalSubscriptions.delete(unpacked.value);
|
|
129
|
+
break;
|
|
130
|
+
case `clear`:
|
|
131
|
+
for (const unsub of disposalSubscriptions.values()) unsub();
|
|
132
|
+
disposalSubscriptions.clear();
|
|
133
|
+
}
|
|
134
|
+
}, `set-auto-deletion-triggers`);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
//#endregion
|
|
138
|
+
export { SET_UPDATE_ENUM, UList, uListDisposedKeyCleanupEffect };
|
|
108
139
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["SET_UPDATE_ENUM: Enumeration<[`add`, `delete`, `clear`]>"],"sources":["../../../src/transceivers/u-list/u-list.ts"],"sourcesContent":["import type { Fn, Transceiver, TransceiverMode } from \"atom.io/internal\"\nimport { Subject } from \"atom.io/internal\"\nimport type { primitive } from \"atom.io/json\"\nimport type { Enumeration } from \"atom.io/struct\"\nimport { enumeration, packValue, unpackValue } from \"atom.io/struct\"\n\nexport type SetMutations = Exclude<\n\tkeyof Set<any>,\n\tsymbol | keyof ReadonlySet<any>\n>\nexport type SetUpdate<P extends primitive> =\n\t| {\n\t\t\ttype: `add` | `delete`\n\t\t\tvalue: P\n\t }\n\t| {\n\t\t\ttype: `clear`\n\t\t\tvalues: P[]\n\t }\nexport type UListUpdateType = SetUpdate<any>[`type`]\ntrue satisfies SetMutations extends UListUpdateType\n\t? true\n\t: Exclude<SetMutations, UListUpdateType>\n\nexport type PackedSetUpdate<P extends primitive> = string & {\n\tupdate?: SetUpdate<P>\n}\n\nexport const SET_UPDATE_ENUM: Enumeration<[`add`, `delete`, `clear`]> =\n\tenumeration([`add`, `delete`, `clear`] as const)\n\nexport type SetMutationHandler = { [K in UListUpdateType]: Fn }\n\nexport type UListView<P extends primitive> = ReadonlySet<P> & {\n\tsubscribe: (\n\t\tkey: string,\n\t\tfn: (update: PackedSetUpdate<P>) => void,\n\t) => () => void\n}\n\nexport class UList<P extends primitive>\n\textends Set<P>\n\timplements\n\t\tTransceiver<UListView<P>, PackedSetUpdate<P>, ReadonlyArray<P>>,\n\t\tSetMutationHandler\n{\n\tpublic mode: TransceiverMode = `record`\n\tpublic readonly subject: Subject<PackedSetUpdate<P>> = new Subject()\n\n\tpublic constructor(values?: Iterable<P>) {\n\t\tsuper(values)\n\t\tif (values instanceof UList) {\n\t\t}\n\t}\n\n\tpublic readonly READONLY_VIEW: UListView<P> = this\n\n\tpublic toJSON(): ReadonlyArray<P> {\n\t\treturn [...this]\n\t}\n\n\tpublic static fromJSON<P extends primitive>(json: ReadonlyArray<P>): UList<P> {\n\t\treturn new UList<P>(json)\n\t}\n\n\tpublic add(value: P): this {\n\t\tconst result = super.add(value)\n\t\tif (this.mode === `record`) {\n\t\t\tthis.emit({ type: `add`, value })\n\t\t}\n\t\treturn result\n\t}\n\n\tpublic clear(): void {\n\t\tconst capturedContents = this.mode === `record` ? [...this] : null\n\t\tsuper.clear()\n\t\tif (capturedContents) {\n\t\t\tthis.emit({ type: `clear`, values: capturedContents })\n\t\t}\n\t}\n\n\tpublic delete(value: P): boolean {\n\t\tconst result = super.delete(value)\n\t\tif (this.mode === `record`) {\n\t\t\tthis.emit({ type: `delete`, value })\n\t\t}\n\t\treturn result\n\t}\n\n\tpublic subscribe(\n\t\tkey: string,\n\t\tfn: (update: PackedSetUpdate<P>) => void,\n\t): () => void {\n\t\treturn this.subject.subscribe(key, fn)\n\t}\n\n\tpublic emit(update: SetUpdate<P>): void {\n\t\tthis.subject.next(UList.packUpdate(update))\n\t}\n\n\tpublic do(packed: PackedSetUpdate<P>): null {\n\t\tthis.mode = `playback`\n\t\tconst update = UList.unpackUpdate(packed)\n\t\tswitch (update.type) {\n\t\t\tcase `add`:\n\t\t\t\tthis.add(update.value)\n\t\t\t\tbreak\n\t\t\tcase `delete`:\n\t\t\t\tthis.delete(update.value)\n\t\t\t\tbreak\n\t\t\tcase `clear`:\n\t\t\t\tthis.clear()\n\t\t}\n\t\tthis.mode = `record`\n\t\treturn null\n\t}\n\n\tpublic undo(packed: PackedSetUpdate<P>): number | null {\n\t\tconst update = UList.unpackUpdate(packed)\n\t\tthis.mode = `playback`\n\t\tswitch (update.type) {\n\t\t\tcase `add`:\n\t\t\t\tthis.delete(update.value)\n\t\t\t\tbreak\n\t\t\tcase `delete`:\n\t\t\t\tthis.add(update.value)\n\t\t\t\tbreak\n\t\t\tcase `clear`: {\n\t\t\t\tconst values = update.values\n\t\t\t\tfor (const v of values) this.add(v)\n\t\t\t}\n\t\t}\n\t\tthis.mode = `record`\n\t\treturn null\n\t}\n\n\tpublic static packUpdate<P extends primitive>(\n\t\tupdate: SetUpdate<P>,\n\t): PackedSetUpdate<P> {\n\t\tconst head = SET_UPDATE_ENUM[update.type] + `\\u001F`\n\t\tif (update.type === `clear`) {\n\t\t\treturn head + update.values.map(packValue).join(`\\u001E`)\n\t\t}\n\t\treturn head + packValue(update.value)\n\t}\n\tpublic static unpackUpdate<P extends primitive>(\n\t\tpacked: PackedSetUpdate<P>,\n\t): SetUpdate<P> {\n\t\tconst [type, tail] = packed.split(`\\u001F`) as [0 | 1 | 2, string]\n\t\tconst head = SET_UPDATE_ENUM[type]\n\t\tif (head === `clear`) {\n\t\t\tconst values = tail.split(`\\u001E`).map(unpackValue) as P[]\n\t\t\treturn { type: `clear`, values }\n\t\t}\n\t\treturn { type: head, value: unpackValue(tail) as P }\n\t}\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["SET_UPDATE_ENUM: Enumeration<[`add`, `delete`, `clear`]>","uListDisposedKeyCleanupEffect: AtomEffect<UList<primitive>>"],"sources":["../../../src/transceivers/u-list/u-list.ts","../../../src/transceivers/u-list/u-list-disposed-key-cleanup-effect.ts"],"sourcesContent":["import type { Fn, Transceiver, TransceiverMode } from \"atom.io/internal\"\nimport { Subject } from \"atom.io/internal\"\nimport type { primitive } from \"atom.io/json\"\nimport type { Enumeration } from \"atom.io/struct\"\nimport { enumeration, packValue, unpackValue } from \"atom.io/struct\"\n\nexport type SetMutations = Exclude<\n\tkeyof Set<any>,\n\tsymbol | keyof ReadonlySet<any>\n>\nexport type SetUpdate<P extends primitive> =\n\t| {\n\t\t\ttype: `add` | `delete`\n\t\t\tvalue: P\n\t }\n\t| {\n\t\t\ttype: `clear`\n\t\t\tvalues: P[]\n\t }\nexport type UListUpdateType = SetUpdate<any>[`type`]\ntrue satisfies SetMutations extends UListUpdateType\n\t? true\n\t: Exclude<SetMutations, UListUpdateType>\n\nexport type PackedSetUpdate<P extends primitive> = string & {\n\tupdate?: SetUpdate<P>\n}\n\nexport const SET_UPDATE_ENUM: Enumeration<[`add`, `delete`, `clear`]> =\n\tenumeration([`add`, `delete`, `clear`] as const)\n\nexport type SetMutationHandler = { [K in UListUpdateType]: Fn }\n\nexport type UListView<P extends primitive> = ReadonlySet<P> & {\n\tsubscribe: (\n\t\tkey: string,\n\t\tfn: (update: PackedSetUpdate<P>) => void,\n\t) => () => void\n}\n\nexport class UList<P extends primitive>\n\textends Set<P>\n\timplements\n\t\tTransceiver<UListView<P>, PackedSetUpdate<P>, ReadonlyArray<P>>,\n\t\tSetMutationHandler\n{\n\tpublic mode: TransceiverMode = `record`\n\tpublic readonly subject: Subject<PackedSetUpdate<P>> = new Subject()\n\n\tpublic constructor(values?: Iterable<P>) {\n\t\tsuper(values)\n\t\tif (values instanceof UList) {\n\t\t}\n\t}\n\n\tpublic readonly READONLY_VIEW: UListView<P> = this\n\n\tpublic toJSON(): ReadonlyArray<P> {\n\t\treturn [...this]\n\t}\n\n\tpublic static fromJSON<P extends primitive>(json: ReadonlyArray<P>): UList<P> {\n\t\treturn new UList<P>(json)\n\t}\n\n\tpublic add(value: P): this {\n\t\tconst result = super.add(value)\n\t\tif (this.mode === `record`) {\n\t\t\tthis.emit({ type: `add`, value })\n\t\t}\n\t\treturn result\n\t}\n\n\tpublic clear(): void {\n\t\tconst capturedContents = this.mode === `record` ? [...this] : null\n\t\tsuper.clear()\n\t\tif (capturedContents) {\n\t\t\tthis.emit({ type: `clear`, values: capturedContents })\n\t\t}\n\t}\n\n\tpublic delete(value: P): boolean {\n\t\tconst result = super.delete(value)\n\t\tif (this.mode === `record`) {\n\t\t\tthis.emit({ type: `delete`, value })\n\t\t}\n\t\treturn result\n\t}\n\n\tpublic subscribe(\n\t\tkey: string,\n\t\tfn: (update: PackedSetUpdate<P>) => void,\n\t): () => void {\n\t\treturn this.subject.subscribe(key, fn)\n\t}\n\n\tpublic emit(update: SetUpdate<P>): void {\n\t\tthis.subject.next(UList.packUpdate(update))\n\t}\n\n\tpublic do(packed: PackedSetUpdate<P>): null {\n\t\tthis.mode = `playback`\n\t\tconst update = UList.unpackUpdate(packed)\n\t\tswitch (update.type) {\n\t\t\tcase `add`:\n\t\t\t\tthis.add(update.value)\n\t\t\t\tbreak\n\t\t\tcase `delete`:\n\t\t\t\tthis.delete(update.value)\n\t\t\t\tbreak\n\t\t\tcase `clear`:\n\t\t\t\tthis.clear()\n\t\t}\n\t\tthis.mode = `record`\n\t\treturn null\n\t}\n\n\tpublic undo(packed: PackedSetUpdate<P>): number | null {\n\t\tconst update = UList.unpackUpdate(packed)\n\t\tthis.mode = `playback`\n\t\tswitch (update.type) {\n\t\t\tcase `add`:\n\t\t\t\tthis.delete(update.value)\n\t\t\t\tbreak\n\t\t\tcase `delete`:\n\t\t\t\tthis.add(update.value)\n\t\t\t\tbreak\n\t\t\tcase `clear`: {\n\t\t\t\tconst values = update.values\n\t\t\t\tfor (const v of values) this.add(v)\n\t\t\t}\n\t\t}\n\t\tthis.mode = `record`\n\t\treturn null\n\t}\n\n\tpublic static packUpdate<P extends primitive>(\n\t\tupdate: SetUpdate<P>,\n\t): PackedSetUpdate<P> {\n\t\tconst head = SET_UPDATE_ENUM[update.type] + `\\u001F`\n\t\tif (update.type === `clear`) {\n\t\t\treturn head + update.values.map(packValue).join(`\\u001E`)\n\t\t}\n\t\treturn head + packValue(update.value)\n\t}\n\tpublic static unpackUpdate<P extends primitive>(\n\t\tpacked: PackedSetUpdate<P>,\n\t): SetUpdate<P> {\n\t\tconst [type, tail] = packed.split(`\\u001F`) as [0 | 1 | 2, string]\n\t\tconst head = SET_UPDATE_ENUM[type]\n\t\tif (head === `clear`) {\n\t\t\tconst values = tail.split(`\\u001E`).map(unpackValue) as P[]\n\t\t\treturn { type: `clear`, values }\n\t\t}\n\t\treturn { type: head, value: unpackValue(tail) as P }\n\t}\n}\n","import type { AtomEffect } from \"atom.io\"\nimport { getUpdateToken, subscribeInStore } from \"atom.io/internal\"\nimport { type primitive, stringifyJson } from \"atom.io/json\"\n\nimport { UList } from \"./u-list\"\n\nexport const uListDisposedKeyCleanupEffect: AtomEffect<UList<primitive>> = ({\n\ttoken,\n\tsetSelf,\n\tstore,\n}) => {\n\tconst disposalSubscriptions = new Map<primitive, () => void>()\n\tconst updateToken = getUpdateToken(token)\n\tsubscribeInStore(\n\t\tstore,\n\t\tupdateToken,\n\t\tfunction setAutoDeletionTriggers({ newValue }) {\n\t\t\tconst unpacked = UList.unpackUpdate(newValue)\n\t\t\tswitch (unpacked.type) {\n\t\t\t\tcase `add`:\n\t\t\t\t\t{\n\t\t\t\t\t\tconst molecule = store.molecules.get(stringifyJson(unpacked.value))\n\t\t\t\t\t\tif (molecule) {\n\t\t\t\t\t\t\tdisposalSubscriptions.set(\n\t\t\t\t\t\t\t\tunpacked.value,\n\t\t\t\t\t\t\t\tmolecule.subject.subscribe(token.key, () => {\n\t\t\t\t\t\t\t\t\tsetSelf((self) => {\n\t\t\t\t\t\t\t\t\t\tself.delete(unpacked.value)\n\t\t\t\t\t\t\t\t\t\treturn self\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\tcase `delete`:\n\t\t\t\t\tdisposalSubscriptions.get(unpacked.value)?.()\n\t\t\t\t\tdisposalSubscriptions.delete(unpacked.value)\n\t\t\t\t\tbreak\n\t\t\t\tcase `clear`:\n\t\t\t\t\tfor (const unsub of disposalSubscriptions.values()) unsub()\n\t\t\t\t\tdisposalSubscriptions.clear()\n\t\t\t}\n\t\t},\n\t\t`set-auto-deletion-triggers`,\n\t)\n}\n"],"mappings":";;;;;AA4BA,MAAaA,kBACZ,YAAY;CAAC;CAAO;CAAU;CAAQ,CAAU;AAWjD,IAAa,QAAb,MAAa,cACJ,IAIT;CACC,AAAO,OAAwB;CAC/B,AAAgB,UAAuC,IAAI,SAAS;CAEpE,AAAO,YAAY,QAAsB;AACxC,QAAM,OAAO;AACb,MAAI,kBAAkB,OAAO;;CAI9B,AAAgB,gBAA8B;CAE9C,AAAO,SAA2B;AACjC,SAAO,CAAC,GAAG,KAAK;;CAGjB,OAAc,SAA8B,MAAkC;AAC7E,SAAO,IAAI,MAAS,KAAK;;CAG1B,AAAO,IAAI,OAAgB;EAC1B,MAAM,SAAS,MAAM,IAAI,MAAM;AAC/B,MAAI,KAAK,SAAS,SACjB,MAAK,KAAK;GAAE,MAAM;GAAO;GAAO,CAAC;AAElC,SAAO;;CAGR,AAAO,QAAc;EACpB,MAAM,mBAAmB,KAAK,SAAS,WAAW,CAAC,GAAG,KAAK,GAAG;AAC9D,QAAM,OAAO;AACb,MAAI,iBACH,MAAK,KAAK;GAAE,MAAM;GAAS,QAAQ;GAAkB,CAAC;;CAIxD,AAAO,OAAO,OAAmB;EAChC,MAAM,SAAS,MAAM,OAAO,MAAM;AAClC,MAAI,KAAK,SAAS,SACjB,MAAK,KAAK;GAAE,MAAM;GAAU;GAAO,CAAC;AAErC,SAAO;;CAGR,AAAO,UACN,KACA,IACa;AACb,SAAO,KAAK,QAAQ,UAAU,KAAK,GAAG;;CAGvC,AA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,wBAAwB,EAAE,YAAY;EAC9C,MAAM,WAAW,MAAM,aAAa,SAAS;AAC7C,UAAQ,SAAS,MAAjB;GACC,KAAK;IACJ;KACC,MAAM,WAAW,MAAM,UAAU,IAAI,cAAc,SAAS,MAAM,CAAC;AACnE,SAAI,SACH,uBAAsB,IACrB,SAAS,OACT,SAAS,QAAQ,UAAU,MAAM,WAAW;AAC3C,eAAS,SAAS;AACjB,YAAK,OAAO,SAAS,MAAM;AAC3B,cAAO;QACN;OACD,CACF;;AAGH;GACD,KAAK;AACJ,0BAAsB,IAAI,SAAS,MAAM,IAAI;AAC7C,0BAAsB,OAAO,SAAS,MAAM;AAC5C;GACD,KAAK;AACJ,SAAK,MAAM,SAAS,sBAAsB,QAAQ,CAAE,QAAO;AAC3D,0BAAsB,OAAO;;IAGhC,6BACA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atom.io",
|
|
3
|
-
"version": "0.42.
|
|
3
|
+
"version": "0.42.2",
|
|
4
4
|
"description": "Composable and testable reactive data library.",
|
|
5
5
|
"homepage": "https://atom.io.fyi",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -60,45 +60,45 @@
|
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@eslint/core": "0.
|
|
64
|
-
"@storybook/addon-docs": "9.1.
|
|
65
|
-
"@storybook/addon-onboarding": "9.1.
|
|
66
|
-
"@storybook/react-vite": "9.1.
|
|
63
|
+
"@eslint/core": "0.16.0",
|
|
64
|
+
"@storybook/addon-docs": "9.1.8",
|
|
65
|
+
"@storybook/addon-onboarding": "9.1.8",
|
|
66
|
+
"@storybook/react-vite": "9.1.8",
|
|
67
67
|
"@testing-library/react": "16.3.0",
|
|
68
|
-
"@types/bun": "npm:bun-types@1.2.
|
|
68
|
+
"@types/bun": "npm:bun-types@1.2.23",
|
|
69
69
|
"@types/eslint": "9.6.1",
|
|
70
70
|
"@types/estree": "1.0.8",
|
|
71
71
|
"@types/http-proxy": "1.17.16",
|
|
72
72
|
"@types/npmlog": "7.0.0",
|
|
73
|
-
"@types/react": "19.1.
|
|
73
|
+
"@types/react": "19.1.15",
|
|
74
74
|
"@types/tmp": "0.2.6",
|
|
75
|
-
"@typescript-eslint/parser": "8.44.
|
|
76
|
-
"@typescript-eslint/rule-tester": "8.44.
|
|
77
|
-
"@typescript-eslint/utils": "8.44.
|
|
75
|
+
"@typescript-eslint/parser": "8.44.1",
|
|
76
|
+
"@typescript-eslint/rule-tester": "8.44.1",
|
|
77
|
+
"@typescript-eslint/utils": "8.44.1",
|
|
78
78
|
"@vitest/coverage-v8": "3.2.4",
|
|
79
79
|
"@vitest/ui": "3.2.4",
|
|
80
80
|
"concurrently": "9.2.1",
|
|
81
|
-
"drizzle-kit": "0.31.
|
|
81
|
+
"drizzle-kit": "0.31.5",
|
|
82
82
|
"drizzle-orm": "0.44.5",
|
|
83
83
|
"eslint": "9.36.0",
|
|
84
|
-
"happy-dom": "
|
|
84
|
+
"happy-dom": "19.0.1",
|
|
85
85
|
"http-proxy": "1.18.1",
|
|
86
|
-
"motion": "12.23.
|
|
86
|
+
"motion": "12.23.22",
|
|
87
87
|
"npmlog": "7.0.1",
|
|
88
88
|
"nyc": "17.1.0",
|
|
89
89
|
"postgres": "3.4.7",
|
|
90
90
|
"preact": "10.27.2",
|
|
91
91
|
"react": "19.1.1",
|
|
92
92
|
"react-dom": "19.1.1",
|
|
93
|
-
"react-router-dom": "7.9.
|
|
93
|
+
"react-router-dom": "7.9.3",
|
|
94
94
|
"recoverage": "0.1.11",
|
|
95
95
|
"socket.io": "4.8.1",
|
|
96
96
|
"socket.io-client": "4.8.1",
|
|
97
|
-
"storybook": "9.1.
|
|
97
|
+
"storybook": "9.1.8",
|
|
98
98
|
"tmp": "0.2.5",
|
|
99
|
-
"tsdown": "0.15.
|
|
99
|
+
"tsdown": "0.15.5",
|
|
100
100
|
"typescript": "5.9.2",
|
|
101
|
-
"vite": "7.1.
|
|
101
|
+
"vite": "7.1.7",
|
|
102
102
|
"vite-tsconfig-paths": "5.1.4",
|
|
103
103
|
"vitest": "3.2.4",
|
|
104
104
|
"zod": "3.25.76",
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
} from "atom.io"
|
|
7
7
|
import type { Canonical } from "atom.io/json"
|
|
8
8
|
|
|
9
|
-
import { newest } from "../lineage"
|
|
9
|
+
import { eldest, newest } from "../lineage"
|
|
10
10
|
import { resetInStore, setIntoStore } from "../set-state"
|
|
11
11
|
import type { RegularAtom } from "../state-types"
|
|
12
12
|
import type { Store } from "../store"
|
|
@@ -68,6 +68,8 @@ export function createRegularAtom<T, K extends Canonical, E>(
|
|
|
68
68
|
},
|
|
69
69
|
onSet: (handle: UpdateHandler<T>) =>
|
|
70
70
|
subscribeToState(store, token, `effect[${effectIndex}]`, handle),
|
|
71
|
+
token: token as any,
|
|
72
|
+
store: eldest(store),
|
|
71
73
|
})
|
|
72
74
|
if (cleanup) {
|
|
73
75
|
cleanupFunctions.push(cleanup)
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
findState,
|
|
3
|
-
getState,
|
|
4
|
-
JoinOptions,
|
|
5
|
-
MutableAtomFamilyToken,
|
|
6
|
-
ReadonlyPureSelectorFamilyToken,
|
|
7
|
-
setState,
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import {
|
|
2
|
+
type findState,
|
|
3
|
+
type getState,
|
|
4
|
+
type JoinOptions,
|
|
5
|
+
type MutableAtomFamilyToken,
|
|
6
|
+
type ReadonlyPureSelectorFamilyToken,
|
|
7
|
+
type setState,
|
|
8
|
+
simpleCompound,
|
|
9
|
+
type Write,
|
|
10
|
+
type WriterToolkit,
|
|
10
11
|
} from "atom.io"
|
|
11
|
-
import { Anarchy } from "atom.io"
|
|
12
|
-
import { stringifyJson } from "atom.io/json"
|
|
13
12
|
import { UList } from "atom.io/transceivers/u-list"
|
|
14
13
|
|
|
15
14
|
import { capitalize } from "../capitalize"
|
|
@@ -86,7 +85,6 @@ export class Join<
|
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
public store: Store
|
|
89
|
-
public realm: Anarchy
|
|
90
88
|
|
|
91
89
|
public [Symbol.dispose](): void {}
|
|
92
90
|
|
|
@@ -97,13 +95,10 @@ export class Join<
|
|
|
97
95
|
type AB = A & B
|
|
98
96
|
|
|
99
97
|
this.store = store
|
|
100
|
-
this.realm = new Anarchy(store)
|
|
101
98
|
this.options = options
|
|
102
99
|
|
|
103
100
|
this.store.miscResources.set(`join:${options.key}`, this)
|
|
104
101
|
|
|
105
|
-
this.realm.allocate(`root`, options.key)
|
|
106
|
-
|
|
107
102
|
this.toolkit = {
|
|
108
103
|
get: ((...ps: Parameters<typeof getState>) =>
|
|
109
104
|
getFromStore(store, ...ps)) as typeof getState,
|
|
@@ -179,9 +174,9 @@ export class Join<
|
|
|
179
174
|
})
|
|
180
175
|
}
|
|
181
176
|
for (const previousOwner of previousOwnersToDispose) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
177
|
+
store.keyRefsInJoins.delete(
|
|
178
|
+
simpleCompound(newRelationB, previousOwner),
|
|
179
|
+
)
|
|
185
180
|
}
|
|
186
181
|
}
|
|
187
182
|
if (!newRelationBIsAlreadyRelated) {
|
|
@@ -222,14 +217,9 @@ export class Join<
|
|
|
222
217
|
getRelatedKeys: (key) =>
|
|
223
218
|
this.toolkit.get(relatedKeysAtoms, key) as UList<A> | UList<B>,
|
|
224
219
|
addRelation: (a, b) => {
|
|
225
|
-
this.store.
|
|
226
|
-
this.store.
|
|
227
|
-
|
|
228
|
-
this.realm.allocate(options.key, a)
|
|
229
|
-
}
|
|
230
|
-
if (!this.store.molecules.has(stringifyJson(b))) {
|
|
231
|
-
this.realm.allocate(options.key, b)
|
|
232
|
-
}
|
|
220
|
+
this.store.keyRefsInJoins.set(`"${a}"`, options.key)
|
|
221
|
+
this.store.keyRefsInJoins.set(`"${b}"`, options.key)
|
|
222
|
+
this.store.keyRefsInJoins.set(simpleCompound(a, b), options.key)
|
|
233
223
|
this.toolkit.set(relatedKeysAtoms, a, (aKeys) => aKeys.add(b))
|
|
234
224
|
this.toolkit.set(relatedKeysAtoms, b, (bKeys) => bKeys.add(a))
|
|
235
225
|
},
|
|
@@ -242,9 +232,8 @@ export class Join<
|
|
|
242
232
|
bKeys.delete(a)
|
|
243
233
|
return bKeys
|
|
244
234
|
})
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
this.store.moleculeJoins.delete(compositeKey)
|
|
235
|
+
const compositeKey = simpleCompound(a, b)
|
|
236
|
+
this.store.keyRefsInJoins.delete(compositeKey)
|
|
248
237
|
},
|
|
249
238
|
replaceRelationsSafely: (a, bs) => {
|
|
250
239
|
replaceRelationsSafely(this.toolkit, a, bs)
|
|
@@ -262,24 +251,6 @@ export class Join<
|
|
|
262
251
|
externalStore,
|
|
263
252
|
isAType: options.isAType,
|
|
264
253
|
isBType: options.isBType,
|
|
265
|
-
// makeContentKey: (...args) => {
|
|
266
|
-
// const [a, b] = args
|
|
267
|
-
// const [x, y] = args.sort()
|
|
268
|
-
// const compositeKey = `${x}:${y}`
|
|
269
|
-
// const aMolecule = store.molecules.get(stringifyJson(a))
|
|
270
|
-
// const bMolecule = store.molecules.get(stringifyJson(b))
|
|
271
|
-
// if (!aMolecule) {
|
|
272
|
-
// this.realm.allocate(options.key, a)
|
|
273
|
-
// }
|
|
274
|
-
// if (!bMolecule) {
|
|
275
|
-
// this.realm.allocate(options.key, b)
|
|
276
|
-
// }
|
|
277
|
-
|
|
278
|
-
// this.realm.allocate(a, compositeKey, `all`)
|
|
279
|
-
// this.realm.claim(b, compositeKey)
|
|
280
|
-
// this.store.moleculeJoins.set(compositeKey, options.key)
|
|
281
|
-
// return compositeKey
|
|
282
|
-
// },
|
|
283
254
|
})
|
|
284
255
|
|
|
285
256
|
const createSingleKeySelectorFamily = () =>
|
package/src/internal/molecule.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
Above,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Hierarchy,
|
|
7
|
-
MoleculeCreationEvent,
|
|
8
|
-
MoleculeDisposalEvent,
|
|
9
|
-
MoleculeTransferEvent,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import {
|
|
2
|
+
type Above,
|
|
3
|
+
type CompoundFrom,
|
|
4
|
+
type CompoundTypedKey,
|
|
5
|
+
decomposeCompound,
|
|
6
|
+
type Hierarchy,
|
|
7
|
+
type MoleculeCreationEvent,
|
|
8
|
+
type MoleculeDisposalEvent,
|
|
9
|
+
type MoleculeTransferEvent,
|
|
10
|
+
simpleCompound,
|
|
11
|
+
type SingularTypedKey,
|
|
12
|
+
type TransactionToken,
|
|
13
|
+
type ValidKey,
|
|
14
|
+
type Vassal,
|
|
13
15
|
} from "atom.io"
|
|
14
16
|
import type { Canonical, stringified } from "atom.io/json"
|
|
15
17
|
import { parseJson, stringifyJson } from "atom.io/json"
|
|
@@ -19,6 +21,7 @@ import { getFromStore } from "./get-state"
|
|
|
19
21
|
import { getTrace } from "./get-trace"
|
|
20
22
|
import { newest } from "./lineage"
|
|
21
23
|
import type { Store } from "./store"
|
|
24
|
+
import { Subject } from "./subject"
|
|
22
25
|
import type { RootStore } from "./transaction"
|
|
23
26
|
import { createTransaction, isChildStore } from "./transaction"
|
|
24
27
|
|
|
@@ -26,6 +29,7 @@ export type Molecule<K extends Canonical> = {
|
|
|
26
29
|
readonly key: K
|
|
27
30
|
readonly stringKey: stringified<K>
|
|
28
31
|
readonly dependsOn: `all` | `any`
|
|
32
|
+
readonly subject: Subject<void>
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
export function makeRootMoleculeInStore<S extends string>(
|
|
@@ -36,6 +40,7 @@ export function makeRootMoleculeInStore<S extends string>(
|
|
|
36
40
|
key,
|
|
37
41
|
stringKey: stringifyJson(key),
|
|
38
42
|
dependsOn: `any`,
|
|
43
|
+
subject: new Subject(),
|
|
39
44
|
} satisfies Molecule<S>
|
|
40
45
|
store.molecules.set(stringifyJson(key), molecule)
|
|
41
46
|
return key
|
|
@@ -50,7 +55,7 @@ export function allocateIntoStore<
|
|
|
50
55
|
provenance: A,
|
|
51
56
|
key: V,
|
|
52
57
|
dependsOn: `all` | `any` = `any`,
|
|
53
|
-
):
|
|
58
|
+
): ValidKey<V> {
|
|
54
59
|
const origin = provenance as Canonical | [Canonical, Canonical]
|
|
55
60
|
const stringKey = stringifyJson(key)
|
|
56
61
|
const invalidKeys: stringified<Canonical>[] = []
|
|
@@ -75,8 +80,9 @@ export function allocateIntoStore<
|
|
|
75
80
|
invalidKeys.push(claimString)
|
|
76
81
|
}
|
|
77
82
|
}
|
|
83
|
+
const subject = new Subject<void>()
|
|
78
84
|
if (invalidKeys.length === 0) {
|
|
79
|
-
target.molecules.set(stringKey, { key, stringKey, dependsOn })
|
|
85
|
+
target.molecules.set(stringKey, { key, stringKey, dependsOn, subject })
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
const creationEvent: MoleculeCreationEvent = {
|
|
@@ -109,7 +115,7 @@ export function allocateIntoStore<
|
|
|
109
115
|
)
|
|
110
116
|
}
|
|
111
117
|
|
|
112
|
-
return key as
|
|
118
|
+
return key as ValidKey<V>
|
|
113
119
|
}
|
|
114
120
|
|
|
115
121
|
export function fuseWithinStore<
|
|
@@ -123,7 +129,7 @@ export function fuseWithinStore<
|
|
|
123
129
|
type: T,
|
|
124
130
|
sideA: SingularTypedKey<A>,
|
|
125
131
|
sideB: SingularTypedKey<B>,
|
|
126
|
-
):
|
|
132
|
+
): ValidKey<CompoundTypedKey<T, A, B>> {
|
|
127
133
|
const compoundKey: CompoundTypedKey<T, A, B> =
|
|
128
134
|
`T$--${type}==${sideA}++${sideB}`
|
|
129
135
|
const above = [sideA, sideB] as Above<Vassal<H>, H>
|
|
@@ -139,10 +145,10 @@ export function fuseWithinStore<
|
|
|
139
145
|
export function createDeallocateTX<
|
|
140
146
|
H extends Hierarchy,
|
|
141
147
|
V extends Exclude<Vassal<H>, CompoundTypedKey>,
|
|
142
|
-
>(store: RootStore): TransactionToken<(claim:
|
|
148
|
+
>(store: RootStore): TransactionToken<(claim: ValidKey<V>) => void> {
|
|
143
149
|
return createTransaction(store, {
|
|
144
150
|
key: `[Internal] deallocate`,
|
|
145
|
-
do: (_, claim:
|
|
151
|
+
do: (_, claim: ValidKey<V>): void => {
|
|
146
152
|
deallocateFromStore<H, V>(newest(store), claim)
|
|
147
153
|
},
|
|
148
154
|
})
|
|
@@ -150,7 +156,7 @@ export function createDeallocateTX<
|
|
|
150
156
|
|
|
151
157
|
export function deallocateFromStore<H extends Hierarchy, V extends Vassal<H>>(
|
|
152
158
|
target: Store,
|
|
153
|
-
claim:
|
|
159
|
+
claim: ValidKey<V>,
|
|
154
160
|
): void {
|
|
155
161
|
const stringKey = stringifyJson(claim)
|
|
156
162
|
|
|
@@ -171,8 +177,9 @@ export function deallocateFromStore<H extends Hierarchy, V extends Vassal<H>>(
|
|
|
171
177
|
)
|
|
172
178
|
return
|
|
173
179
|
}
|
|
180
|
+
molecule.subject.next()
|
|
174
181
|
|
|
175
|
-
const joinKeys = target.
|
|
182
|
+
const joinKeys = target.keyRefsInJoins.getRelatedKeys(stringKey)
|
|
176
183
|
if (joinKeys) {
|
|
177
184
|
for (const joinKey of joinKeys) {
|
|
178
185
|
const join = target.joins.get(joinKey)
|
|
@@ -180,8 +187,20 @@ export function deallocateFromStore<H extends Hierarchy, V extends Vassal<H>>(
|
|
|
180
187
|
join.relations.delete(claim)
|
|
181
188
|
}
|
|
182
189
|
}
|
|
190
|
+
} else {
|
|
191
|
+
const compound = decomposeCompound(claim)
|
|
192
|
+
if (compound) {
|
|
193
|
+
const [, a, b] = compound
|
|
194
|
+
const joinKey = target.keyRefsInJoins.getRelatedKey(simpleCompound(a, b))
|
|
195
|
+
if (joinKey) {
|
|
196
|
+
const join = target.joins.get(joinKey)
|
|
197
|
+
if (join) {
|
|
198
|
+
join.relations.delete(a, b)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
183
202
|
}
|
|
184
|
-
target.
|
|
203
|
+
target.keyRefsInJoins.delete(stringKey)
|
|
185
204
|
|
|
186
205
|
const provenance: stringified<Canonical>[] = []
|
|
187
206
|
|
|
@@ -225,7 +244,7 @@ export function deallocateFromStore<H extends Hierarchy, V extends Vassal<H>>(
|
|
|
225
244
|
}
|
|
226
245
|
|
|
227
246
|
target.moleculeGraph.delete(molecule.stringKey)
|
|
228
|
-
target.
|
|
247
|
+
target.keyRefsInJoins.delete(molecule.stringKey)
|
|
229
248
|
target.moleculeData.delete(molecule.stringKey)
|
|
230
249
|
|
|
231
250
|
if (!isTransaction) {
|
|
@@ -244,7 +263,7 @@ export function createClaimTX<
|
|
|
244
263
|
>(
|
|
245
264
|
store: RootStore,
|
|
246
265
|
): TransactionToken<
|
|
247
|
-
(newProvenance: A, claim:
|
|
266
|
+
(newProvenance: A, claim: ValidKey<V>, exclusive?: `exclusive`) => void
|
|
248
267
|
> {
|
|
249
268
|
return createTransaction(store, {
|
|
250
269
|
key: `[Internal] claim`,
|
|
@@ -261,9 +280,9 @@ export function claimWithinStore<
|
|
|
261
280
|
>(
|
|
262
281
|
store: Store,
|
|
263
282
|
newProvenance: A,
|
|
264
|
-
claim:
|
|
283
|
+
claim: ValidKey<V>,
|
|
265
284
|
exclusive?: `exclusive`,
|
|
266
|
-
):
|
|
285
|
+
): ValidKey<V> {
|
|
267
286
|
const stringKey = stringifyJson(claim)
|
|
268
287
|
const target = newest(store)
|
|
269
288
|
const molecule = target.molecules.get(stringKey)
|