Commit 146e95b
authored
add EditorAtom helper (tldraw#6531)
When I was working on the workflows starter, I found myself needing to
store a lot of state in atoms. This includes:
* The current exectution
* Which ports on which shapes should be highlighted when dragging a
connection
* Whether the on-canvas component picker was visible, and which shape it
should be attached to
All of this state should really belong to a specific `Editor` instance.
It's referencing data from that instance. If I was building a full app
and navigated from one workflow to another, I would want all the state
to be cleared due to the editor getting re-created. It's possible to get
this sort of functionality by using a weak map from editors to atoms,
but it takes a fair bit of management.
This diff adds an `EditorAtom` helper which handles the weak-map
juggling. The interface is similar to that of `Editor`, but each method
takes an `editor` for scoping.
### Change type
- [x] `api`
### Release notes
### API Changes
- Added `EditorAtom`, a helper for storing editor UI state in an `Atom`1 parent fa37496 commit 146e95b
3 files changed
Lines changed: 51 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1549 | 1549 | | |
1550 | 1550 | | |
1551 | 1551 | | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
1552 | 1565 | | |
1553 | 1566 | | |
1554 | 1567 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
450 | 450 | | |
451 | 451 | | |
452 | 452 | | |
| 453 | + | |
453 | 454 | | |
454 | 455 | | |
455 | 456 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
0 commit comments