| 12 | * @public |
| 13 | */ |
| 14 | export class EditorAtom<T> { |
| 15 | private states = new WeakCache<Editor, Atom<T>>() |
| 16 | |
| 17 | constructor( |
| 18 | private name: string, |
| 19 | private getInitialState: (editor: Editor) => T |
| 20 | ) {} |
| 21 | |
| 22 | getAtom(editor: Editor): Atom<T> { |
| 23 | return this.states.get(editor, () => atom(this.name, this.getInitialState(editor))) |
| 24 | } |
| 25 | |
| 26 | get(editor: Editor): T { |
| 27 | return this.getAtom(editor).get() |
| 28 | } |
| 29 | |
| 30 | update(editor: Editor, update: (state: T) => T): T { |
| 31 | return this.getAtom(editor).update(update) |
| 32 | } |
| 33 | |
| 34 | set(editor: Editor, state: T): T { |
| 35 | return this.getAtom(editor).set(state) |
| 36 | } |
| 37 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…