derived presence state (#1204)
This PR adds - A new `TLInstancePresence` record type, to collect info about the presence state in a particular instance of the editor. This will eventually be used to sync presence data instead of sending instance-only state across the wire. - **Record Scopes** `RecordType` now has a `scope` property which can be one of three things: - `document`: the record belongs to the document and should be synced and persisted freely. Currently: `TLDocument`, `TLPage`, `TLShape`, and `TLAsset` - `instance`: the record belongs to a single instance of the store and should not be synced at all. It should not be persisted directly in most cases, but rather compiled into a kind of 'instance configuration' to store alongside the local document data so that when reopening the associated document it can remember some of the previous instance state. Currently: `TLInstance`, `TLInstancePageState`, `TLCamera`, `TLUser`, `TLUserDocument`, `TLUserPresence` - `presence`: the record belongs to a single instance of the store and should not be persisted, but may be synced using the special presence sync protocol. Currently just `TLInstancePresence` This sets us up for the following changes, which are gonna be pretty high-impact in terms of integrating tldraw into existing systems: - Removing `instanceId` as a config option. Each instance gets a randomly generated ID. - We'd replace it with an `instanceConfig` option that has stuff like selectedIds, camera positions, and so on. Then it's up to library users to get and reinstate the instance config at persistence boundaries. - Removing `userId` as config option, and removing the `TLUser` type altogether. - We might need to revisit when doing auth-enabled features like locking shapes, but I suspect that will be separate.
This commit is contained in:
parent
da613ea6ef
commit
731da1bc77
40 changed files with 396 additions and 93 deletions
|
@ -37,6 +37,13 @@ export type ErrorResult<E> = {
|
|||
// @internal (undocumented)
|
||||
export function exhaustiveSwitchError(value: never, property?: string): never;
|
||||
|
||||
// @internal
|
||||
export function filterEntries<Key extends string, Value>(object: {
|
||||
[K in Key]: Value;
|
||||
}, predicate: (key: Key, value: Value) => boolean): {
|
||||
[K in Key]: Value;
|
||||
};
|
||||
|
||||
// @internal (undocumented)
|
||||
export function getErrorAnnotations(error: Error): ErrorAnnotations;
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ export { getFirstFromIterable } from './lib/iterable'
|
|||
export { lerp, modulate, rng } from './lib/number'
|
||||
export {
|
||||
deepCopy,
|
||||
filterEntries,
|
||||
getOwnProperty,
|
||||
hasOwnProperty,
|
||||
objectMapEntries,
|
||||
|
|
|
@ -87,3 +87,24 @@ export function objectMapEntries<Key extends string, Value>(object: {
|
|||
}): Array<[Key, Value]> {
|
||||
return Object.entries(object) as [Key, Value][]
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters an object using a predicate function.
|
||||
* @returns a new object with only the entries that pass the predicate
|
||||
* @internal
|
||||
*/
|
||||
export function filterEntries<Key extends string, Value>(
|
||||
object: { [K in Key]: Value },
|
||||
predicate: (key: Key, value: Value) => boolean
|
||||
): { [K in Key]: Value } {
|
||||
const result: { [K in Key]?: Value } = {}
|
||||
let didChange = false
|
||||
for (const [key, value] of objectMapEntries(object)) {
|
||||
if (predicate(key, value)) {
|
||||
result[key] = value
|
||||
} else {
|
||||
didChange = true
|
||||
}
|
||||
}
|
||||
return didChange ? (result as { [K in Key]: Value }) : object
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue