| 18 | * prevent bugs that could be caused from using the same state with two different documents. |
| 19 | */ |
| 20 | export 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 |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…