2
2
* @todo Things that still need to be done before this can be called done:
3
3
*
4
4
* 1. Fill out all incomplete methods
5
- * 2. Make sure the class respects the resyncOnNewSubscription option
6
- * 3. Add tests
7
- * 4. See if there's a way to make sure that if you provide a type parameter to
5
+ * 2. Add tests
6
+ * 3. See if there's a way to make sure that if you provide a type parameter to
8
7
* the hook, you must also provide a select function
9
8
*/
10
9
import {
@@ -40,21 +39,6 @@ type ReactTimeSyncSubscriptionEntry = Readonly<
40
39
}
41
40
> ;
42
41
43
- type ReactTimeSyncInitOptions = Readonly <
44
- TimeSyncInitOptions & {
45
- /**
46
- * Configures whether adding a new subscription will immediately create
47
- * a new time snapshot and use it to update all other subscriptions.
48
- */
49
- resyncOnNewSubscription : boolean ;
50
- }
51
- > ;
52
-
53
- const defaultReactTimeSyncOptions : ReactTimeSyncInitOptions = {
54
- ...defaultOptions ,
55
- resyncOnNewSubscription : true ,
56
- } ;
57
-
58
42
interface ReactTimeSyncApi {
59
43
subscribe : ( entry : ReactTimeSyncSubscriptionEntry ) => ( ) => void ;
60
44
getSelectionSnapshot : < T = unknown > ( id : string ) => T ;
@@ -65,9 +49,9 @@ class ReactTimeSync implements ReactTimeSyncApi {
65
49
readonly #resyncOnNewSubscription: boolean ;
66
50
readonly #selectionCache: Map < string , unknown > ;
67
51
68
- constructor ( options : Partial < ReactTimeSyncInitOptions > ) {
52
+ constructor ( options : Partial < TimeSyncInitOptions > ) {
69
53
const {
70
- resyncOnNewSubscription = defaultReactTimeSyncOptions . resyncOnNewSubscription ,
54
+ resyncOnNewSubscription = defaultOptions . resyncOnNewSubscription ,
71
55
initialDatetime = defaultOptions . initialDatetime ,
72
56
createNewDatetime = defaultOptions . createNewDatetime ,
73
57
setInterval = defaultOptions . setInterval ,
@@ -101,7 +85,7 @@ const timeSyncContext = createContext<ReactTimeSync | null>(null);
101
85
102
86
type TimeSyncProviderProps = Readonly <
103
87
PropsWithChildren < {
104
- options ?: Partial < ReactTimeSyncInitOptions > ;
88
+ options ?: Partial < TimeSyncInitOptions > ;
105
89
} >
106
90
> ;
107
91
@@ -122,7 +106,7 @@ export const TimeSyncProvider: FC<TimeSyncProviderProps> = ({
122
106
// be treated like a pseudo-ref value, where its values can only be used in
123
107
// very specific, React-approved ways
124
108
const [ readonlySync ] = useState (
125
- ( ) => new ReactTimeSync ( options ?? defaultReactTimeSyncOptions ) ,
109
+ ( ) => new ReactTimeSync ( options ?? defaultOptions ) ,
126
110
) ;
127
111
128
112
return (
0 commit comments