@@ -20,7 +20,7 @@ export interface DittoProviderProps {
20
20
*
21
21
* Returns a single Ditto instance or an array of instances.
22
22
*/
23
- setup : ( ) => Ditto | Ditto [ ]
23
+ setup : ( ) => Ditto | Ditto [ ] | Promise < Ditto | Ditto [ ] >
24
24
render ?: RenderFunction
25
25
children ?: RenderFunction
26
26
}
@@ -65,16 +65,30 @@ export const DittoProvider: React.FunctionComponent<DittoProviderProps> = (
65
65
hasMountEffectStarted . current = true
66
66
try {
67
67
await init ( props . initOptions )
68
- const setupReturnValue : Ditto | Ditto [ ] = props . setup ( )
68
+ const setupReturnValue : Ditto | Ditto [ ] = await props . setup ( )
69
69
if ( Array . isArray ( setupReturnValue ) ) {
70
70
const dittoHash : DittoHash = { }
71
71
const dittos : Ditto [ ] = setupReturnValue
72
72
for ( const ditto of dittos ) {
73
+ if ( ! ( ditto instanceof Ditto ) ) {
74
+ throw new Error (
75
+ // Type is `never` because correct use never reaches this point
76
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
77
+ `expected an array of Ditto instances to be returned by the setup function, but at least one element is not a Ditto instance (got ${ ditto } )` ,
78
+ )
79
+ }
73
80
dittoHash [ ditto . persistenceDirectory ] = ditto
74
81
}
75
82
setDittoHash ( dittoHash )
76
83
} else {
77
84
const ditto = setupReturnValue
85
+ if ( ! ( ditto instanceof Ditto ) ) {
86
+ throw new Error (
87
+ // Type is `never` because correct use never reaches this point
88
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
89
+ `expected a Ditto instance to be returned by the setup function, but got ${ ditto } ` ,
90
+ )
91
+ }
78
92
const dittoHash : DittoHash = { }
79
93
dittoHash [ ditto . persistenceDirectory ] = ditto
80
94
setDittoHash ( dittoHash )
0 commit comments