@@ -43,10 +43,7 @@ type ReactSubscriptionEntry = Readonly<
43
43
// try to retrieve a value, it's easy to differentiate between a value being
44
44
// undefined because that's an explicit selection value, versus it being
45
45
// undefined because we forgot to set it in the cache
46
- type SelectionCacheEntry = Readonly < {
47
- value : unknown ;
48
- select ?: SelectCallback ;
49
- } > ;
46
+ type SelectionCacheEntry = Readonly < { value : unknown } > ;
50
47
51
48
interface ReactTimeSyncApi {
52
49
subscribe : ( entry : ReactSubscriptionEntry ) => ( ) => void ;
@@ -69,15 +66,6 @@ class ReactTimeSync implements ReactTimeSyncApi {
69
66
subscribe = ( entry : ReactSubscriptionEntry ) : ( ( ) => void ) => {
70
67
const { select, id, idealRefreshIntervalMs, onUpdate } = entry ;
71
68
72
- const updateCacheEntry = ( ) => {
73
- const date = this . #timeSync. getTimeSnapshot ( ) ;
74
- const cacheValue = select ?.( date ) ?? date ;
75
- this . #selectionCache. set ( id , {
76
- value : cacheValue ,
77
- select,
78
- } ) ;
79
- } ;
80
-
81
69
// Make sure that we subscribe first, in case TimeSync is configured to
82
70
// invalidate the snapshot on a new subscription. Want to remove risk of
83
71
// stale data
@@ -91,13 +79,16 @@ class ReactTimeSync implements ReactTimeSyncApi {
91
79
return ;
92
80
}
93
81
94
- updateCacheEntry ( ) ;
82
+ this . #selectionCache . set ( id , { value : newSelection } ) ;
95
83
onUpdate ( newDate ) ;
96
84
} ,
97
85
} ;
98
86
this . #timeSync. subscribe ( patchedEntry ) ;
99
87
100
- updateCacheEntry ( ) ;
88
+ const date = this . #timeSync. getTimeSnapshot ( ) ;
89
+ const cacheValue = select ?.( date ) ?? date ;
90
+ this . #selectionCache. set ( id , { value : cacheValue } ) ;
91
+
101
92
return ( ) => this . #timeSync. unsubscribe ( id ) ;
102
93
} ;
103
94
@@ -127,13 +118,7 @@ class ReactTimeSync implements ReactTimeSyncApi {
127
118
128
119
const dateSnapshot = this . #timeSync. getTimeSnapshot ( ) ;
129
120
const newSelection = select ?.( dateSnapshot ) ?? dateSnapshot ;
130
-
131
- // Keep the old select callback, because only that version will be
132
- // memoized via useEffectEvent
133
- this . #selectionCache. set ( id , {
134
- value : newSelection ,
135
- select : cacheEntry . select ,
136
- } ) ;
121
+ this . #selectionCache. set ( id , { value : newSelection } ) ;
137
122
} ;
138
123
}
139
124
0 commit comments