@tldraw/store
Advanced tools
Comparing version 2.0.0-canary.5a9f3a17261a to 2.0.0-canary.5cb08711c19c
@@ -1,3 +0,3 @@ | ||
import { Atom } from 'signia'; | ||
import { Computed } from 'signia'; | ||
import { Atom } from '@tldraw/state'; | ||
import { Computed } from '@tldraw/state'; | ||
@@ -4,0 +4,0 @@ /** |
@@ -26,5 +26,5 @@ "use strict"; | ||
module.exports = __toCommonJS(Store_exports); | ||
var import_state = require("@tldraw/state"); | ||
var import_utils = require("@tldraw/utils"); | ||
var import_nanoid = require("nanoid"); | ||
var import_signia = require("signia"); | ||
var import_Cache = require("./Cache"); | ||
@@ -44,3 +44,3 @@ var import_StoreQueries = require("./StoreQueries"); | ||
*/ | ||
atoms = (0, import_signia.atom)("store_atoms", {}); | ||
atoms = (0, import_state.atom)("store_atoms", {}); | ||
/** | ||
@@ -52,3 +52,3 @@ * An atom containing the store's history. | ||
*/ | ||
history = (0, import_signia.atom)("history", 0, { | ||
history = (0, import_state.atom)("history", 0, { | ||
historyLength: 1e3 | ||
@@ -94,3 +94,3 @@ }); | ||
id, | ||
(0, import_signia.atom)("atom:" + id, this.schema.validateRecord(this, record, "initialize", null)) | ||
(0, import_state.atom)("atom:" + id, this.schema.validateRecord(this, record, "initialize", null)) | ||
]) | ||
@@ -100,3 +100,3 @@ ) | ||
} | ||
this.historyReactor = (0, import_signia.reactor)( | ||
this.historyReactor = (0, import_state.reactor)( | ||
"Store.historyReactor", | ||
@@ -225,3 +225,3 @@ () => { | ||
put = (records, phaseOverride) => { | ||
(0, import_signia.transact)(() => { | ||
(0, import_state.transact)(() => { | ||
const updates = {}; | ||
@@ -262,3 +262,3 @@ const additions = {}; | ||
} | ||
map[record.id] = (0, import_signia.atom)("atom:" + record.id, record); | ||
map[record.id] = (0, import_state.atom)("atom:" + record.id, record); | ||
} | ||
@@ -296,3 +296,3 @@ } | ||
remove = (ids) => { | ||
(0, import_signia.transact)(() => { | ||
(0, import_state.transact)(() => { | ||
if (this.onBeforeDelete && this._runCallbacks) { | ||
@@ -399,3 +399,3 @@ for (const id of ids) { | ||
} | ||
(0, import_signia.transact)(() => { | ||
(0, import_state.transact)(() => { | ||
this.clear(); | ||
@@ -487,3 +487,3 @@ this.put(Object.values(migrationResult.value)); | ||
this.isMergingRemoteChanges = true; | ||
(0, import_signia.transact)(fn); | ||
(0, import_state.transact)(fn); | ||
} finally { | ||
@@ -497,3 +497,3 @@ this.isMergingRemoteChanges = false; | ||
try { | ||
(0, import_signia.transact)(fn); | ||
(0, import_state.transact)(fn); | ||
return squashRecordDiffs(changes); | ||
@@ -508,3 +508,3 @@ } finally { | ||
this._runCallbacks = runCallbacks; | ||
(0, import_signia.transact)(() => { | ||
(0, import_state.transact)(() => { | ||
const toPut = (0, import_utils.objectMapValues)(diff.added).concat( | ||
@@ -542,3 +542,3 @@ (0, import_utils.objectMapValues)(diff.updated).map(([_from, to]) => to) | ||
atom2, | ||
() => (0, import_signia.computed)(name + ":" + id, () => derive(atom2.value)) | ||
() => (0, import_state.computed)(name + ":" + id, () => derive(atom2.value)) | ||
).value; | ||
@@ -564,3 +564,3 @@ } | ||
} | ||
const d = (0, import_signia.computed)( | ||
const d = (0, import_state.computed)( | ||
name + ":" + id + ":selector", | ||
@@ -571,3 +571,3 @@ () => selector(atom2.value) | ||
atom2, | ||
() => (0, import_signia.computed)(name + ":" + id, () => derive(d.value)) | ||
() => (0, import_state.computed)(name + ":" + id, () => derive(d.value)) | ||
).value; | ||
@@ -574,0 +574,0 @@ } |
@@ -34,5 +34,5 @@ "use strict"; | ||
module.exports = __toCommonJS(StoreQueries_exports); | ||
var import_state = require("@tldraw/state"); | ||
var import_utils = require("@tldraw/utils"); | ||
var import_lodash = __toESM(require("lodash.isequal")); | ||
var import_signia = require("signia"); | ||
var import_executeQuery = require("./executeQuery"); | ||
@@ -69,10 +69,10 @@ var import_IncrementalSetConstructor = require("./IncrementalSetConstructor"); | ||
} | ||
const filtered = (0, import_signia.computed)( | ||
const filtered = (0, import_state.computed)( | ||
"filterHistory:" + typeName, | ||
(lastValue, lastComputedEpoch) => { | ||
if ((0, import_signia.isUninitialized)(lastValue)) { | ||
if ((0, import_state.isUninitialized)(lastValue)) { | ||
return this.history.value; | ||
} | ||
const diff = this.history.getDiffSince(lastComputedEpoch); | ||
if (diff === import_signia.RESET_VALUE) | ||
if (diff === import_state.RESET_VALUE) | ||
return this.history.value; | ||
@@ -130,3 +130,3 @@ const res = { added: {}, removed: {}, updated: {} }; | ||
if (numAdded || numRemoved || numUpdated) { | ||
return (0, import_signia.withDiff)(this.history.value, res); | ||
return (0, import_state.withDiff)(this.history.value, res); | ||
} else { | ||
@@ -181,9 +181,9 @@ return lastValue; | ||
}; | ||
return (0, import_signia.computed)( | ||
return (0, import_state.computed)( | ||
"index:" + typeName + ":" + property, | ||
(prevValue, lastComputedEpoch) => { | ||
if ((0, import_signia.isUninitialized)(prevValue)) | ||
if ((0, import_state.isUninitialized)(prevValue)) | ||
return fromScratch(); | ||
const history = typeHistory.getDiffSince(lastComputedEpoch); | ||
if (history === import_signia.RESET_VALUE) { | ||
if (history === import_state.RESET_VALUE) { | ||
return fromScratch(); | ||
@@ -250,3 +250,3 @@ } | ||
if (nextValue && nextDiff) { | ||
return (0, import_signia.withDiff)(nextValue, nextDiff); | ||
return (0, import_state.withDiff)(nextValue, nextDiff); | ||
} | ||
@@ -269,3 +269,3 @@ return prevValue; | ||
const ids = this.ids(typeName, queryCreator, name); | ||
return (0, import_signia.computed)(name, () => { | ||
return (0, import_state.computed)(name, () => { | ||
for (const id of ids.value) { | ||
@@ -286,3 +286,3 @@ return this.atoms.value[id]?.value; | ||
const ids = this.ids(typeName, queryCreator, "ids:" + name); | ||
return (0, import_signia.computed)(name, () => { | ||
return (0, import_state.computed)(name, () => { | ||
return [...ids.value].map((id) => { | ||
@@ -327,3 +327,3 @@ const atom = this.atoms.value[id]; | ||
if (diff) { | ||
return (0, import_signia.withDiff)(nextValue, diff); | ||
return (0, import_state.withDiff)(nextValue, diff); | ||
} else { | ||
@@ -333,10 +333,10 @@ return prevValue; | ||
}; | ||
const cachedQuery = (0, import_signia.computed)("ids_query:" + name, queryCreator, { | ||
const cachedQuery = (0, import_state.computed)("ids_query:" + name, queryCreator, { | ||
isEqual: import_lodash.default | ||
}); | ||
return (0, import_signia.computed)( | ||
return (0, import_state.computed)( | ||
"query:" + name, | ||
(prevValue, lastComputedEpoch) => { | ||
const query = cachedQuery.value; | ||
if ((0, import_signia.isUninitialized)(prevValue)) { | ||
if ((0, import_state.isUninitialized)(prevValue)) { | ||
return fromScratch(); | ||
@@ -348,3 +348,3 @@ } | ||
const history = typeHistory.getDiffSince(lastComputedEpoch); | ||
if (history === import_signia.RESET_VALUE) { | ||
if (history === import_state.RESET_VALUE) { | ||
return fromScratchWithDiff(prevValue); | ||
@@ -380,3 +380,3 @@ } | ||
} | ||
return (0, import_signia.withDiff)(result.value, result.diff); | ||
return (0, import_state.withDiff)(result.value, result.diff); | ||
}, | ||
@@ -389,3 +389,3 @@ { historyLength: 50 } | ||
if (ids.size === 0) { | ||
return import_signia.EMPTY_ARRAY; | ||
return import_state.EMPTY_ARRAY; | ||
} | ||
@@ -392,0 +392,0 @@ const atoms = this.atoms.value; |
{ | ||
"name": "@tldraw/store", | ||
"description": "A tiny little drawing app (store).", | ||
"version": "2.0.0-canary.5a9f3a17261a", | ||
"version": "2.0.0-canary.5cb08711c19c", | ||
"packageManager": "yarn@3.5.0", | ||
@@ -45,9 +45,7 @@ "author": { | ||
"dependencies": { | ||
"@tldraw/utils": "2.0.0-canary.5a9f3a17261a", | ||
"@tldraw/state": "2.0.0-canary.5cb08711c19c", | ||
"@tldraw/utils": "2.0.0-canary.5cb08711c19c", | ||
"lodash.isequal": "^4.5.0", | ||
"nanoid": "4.0.2" | ||
}, | ||
"peerDependencies": { | ||
"signia": "*" | ||
}, | ||
"devDependencies": { | ||
@@ -54,0 +52,0 @@ "@peculiar/webcrypto": "^1.4.0", |
@@ -0,1 +1,2 @@ | ||
import { Atom, Computed, Reactor, atom, computed, reactor, transact } from '@tldraw/state' | ||
import { | ||
@@ -10,3 +11,2 @@ filterEntries, | ||
import { nanoid } from 'nanoid' | ||
import { Atom, Computed, Reactor, atom, computed, reactor, transact } from 'signia' | ||
import { IdOf, RecordId, UnknownRecord } from './BaseRecord' | ||
@@ -13,0 +13,0 @@ import { Cache } from './Cache' |
@@ -1,3 +0,1 @@ | ||
import { objectMapValues } from '@tldraw/utils' | ||
import isEqual from 'lodash.isequal' | ||
import { | ||
@@ -11,3 +9,5 @@ Atom, | ||
withDiff, | ||
} from 'signia' | ||
} from '@tldraw/state' | ||
import { objectMapValues } from '@tldraw/utils' | ||
import isEqual from 'lodash.isequal' | ||
import { IdOf, UnknownRecord } from './BaseRecord' | ||
@@ -14,0 +14,0 @@ import { executeQuery, objectMatchesQuery, QueryExpression } from './executeQuery' |
@@ -1,2 +0,2 @@ | ||
import { Computed, react, RESET_VALUE, transact } from 'signia' | ||
import { Computed, react, RESET_VALUE, transact } from '@tldraw/state' | ||
import { BaseRecord, RecordId } from '../BaseRecord' | ||
@@ -3,0 +3,0 @@ import { createRecordType } from '../RecordType' |
@@ -1,2 +0,2 @@ | ||
import { atom, EffectScheduler, RESET_VALUE } from 'signia' | ||
import { atom, EffectScheduler, RESET_VALUE } from '@tldraw/state' | ||
import { BaseRecord, IdOf, RecordId, UnknownRecord } from '../BaseRecord' | ||
@@ -3,0 +3,0 @@ import { executeQuery } from '../executeQuery' |
@@ -1,2 +0,2 @@ | ||
import { atom, RESET_VALUE } from 'signia' | ||
import { atom, RESET_VALUE } from '@tldraw/state' | ||
import { BaseRecord, RecordId } from '../BaseRecord' | ||
@@ -3,0 +3,0 @@ import { createRecordType } from '../RecordType' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
578412
+ Added@tldraw/state@2.0.0-canary.5cb08711c19c(transitive)
+ Added@tldraw/utils@2.0.0-canary.5cb08711c19c(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedreact@18.3.1(transitive)
- Removed@tldraw/utils@2.0.0-canary.5a9f3a17261a(transitive)
- Removedsignia@0.1.5(transitive)