MCPcopy
hub / github.com/tldraw/tldraw / EditorAtom

Class EditorAtom

templates/workflow/src/utils.ts:20–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18 * prevent bugs that could be caused from using the same state with two different documents.
19 */
20export class EditorAtom<T> {
21 private states = new WeakCache<Editor, Atom<T>>()
22 constructor(
23 private name: string,
24 private getInitialState: (editor: Editor) => T
25 ) {}
26
27 getAtom(editor: Editor) {
28 return this.states.get(editor, () => atom(this.name, this.getInitialState(editor)))
29 }
30
31 get(editor: Editor) {
32 return this.getAtom(editor).get()
33 }
34
35 update(editor: Editor, update: (state: T) => T) {
36 return this.getAtom(editor).update(update)
37 }
38
39 set(editor: Editor, state: T) {
40 return this.getAtom(editor).set(state)
41 }
42}
43
44/**
45 * A list of items keyed by fractional indices. This is useful for collaborative editing, very

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…