atom.io 0.14.3 → 0.14.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,31 +58,29 @@ export function useTL(token: TimelineToken): TimelineMeta {
58
58
  const store = React.useContext(StoreContext)
59
59
  const id = React.useId()
60
60
  const timeline = withdraw(token, store)
61
- if (timeline === undefined) {
62
- store.logger.error(
63
- `❌`,
64
- `timeline`,
65
- token.key,
66
- `Failed to use timeline because it does not exist`,
67
- )
68
- return {
69
- at: NaN,
70
- length: NaN,
71
- undo: () => {},
72
- redo: () => {},
73
- }
74
- }
75
- const meta = React.useRef<TimelineMeta>({
76
- at: timeline.at,
77
- length: timeline.history.length,
61
+ const base = React.useRef({
78
62
  undo: () => undo(token),
79
63
  redo: () => redo(token),
80
64
  })
65
+ const rebuildMeta = React.useCallback(() => {
66
+ return Object.assign(
67
+ {
68
+ at: timeline?.at ?? NaN,
69
+ length: timeline?.history.length ?? NaN,
70
+ },
71
+ base.current,
72
+ )
73
+ }, [])
74
+ const meta = React.useRef<TimelineMeta>(rebuildMeta())
81
75
  const retrieve = React.useCallback(() => {
82
- meta.current.at = timeline.at
83
- meta.current.length = timeline.history.length
76
+ if (
77
+ meta.current.at !== timeline?.at ||
78
+ meta.current.length !== timeline?.history.length
79
+ ) {
80
+ meta.current = rebuildMeta()
81
+ }
84
82
  return meta.current
85
- }, [meta])
83
+ }, [])
86
84
  return React.useSyncExternalStore<TimelineMeta>(
87
85
  (dispatch) => subscribeToTimeline(token, dispatch, `use-tl:${id}`, store),
88
86
  retrieve,