@@ -14,11 +14,12 @@ async function loadFile(source: number) {
1414 return RiveFileFactory . fromSource ( source , undefined ) ;
1515}
1616
17- async function createGordonInstanceAsync ( ) : Promise < ViewModelInstance > {
18- const file = await loadFile ( DATABINDING ) ;
19- const vm = await file . viewModelByNameAsync ( 'Person' ) ;
17+ function createGordonInstance (
18+ file : Awaited < ReturnType < typeof loadFile > >
19+ ) : ViewModelInstance {
20+ const vm = file . viewModelByName ( 'Person' ) ;
2021 expectDefined ( vm ) ;
21- const instance = await vm . createInstanceByNameAsync ( 'Gordon' ) ;
22+ const instance = vm . createInstanceByName ( 'Gordon' ) ;
2223 expectDefined ( instance ) ;
2324 return instance ;
2425}
@@ -36,7 +37,7 @@ function getRGB(color: number): { r: number; g: number; b: number } {
3637describe ( 'Async ViewModel Creation' , ( ) => {
3738 it ( 'createDefaultInstanceAsync returns a valid instance' , async ( ) => {
3839 const file = await loadFile ( DATABINDING ) ;
39- const vm = await file . viewModelByNameAsync ( 'Person' ) ;
40+ const vm = file . viewModelByName ( 'Person' ) ;
4041 expectDefined ( vm ) ;
4142
4243 const instance = await vm . createDefaultInstanceAsync ( ) ;
@@ -46,7 +47,7 @@ describe('Async ViewModel Creation', () => {
4647
4748 it ( 'createInstanceByNameAsync("Gordon") returns named instance' , async ( ) => {
4849 const file = await loadFile ( DATABINDING ) ;
49- const vm = await file . viewModelByNameAsync ( 'Person' ) ;
50+ const vm = file . viewModelByName ( 'Person' ) ;
5051 expectDefined ( vm ) ;
5152
5253 const instance = await vm . createInstanceByNameAsync ( 'Gordon' ) ;
@@ -55,7 +56,7 @@ describe('Async ViewModel Creation', () => {
5556
5657 it ( 'createInstanceByNameAsync with non-existent name returns undefined or throws' , async ( ) => {
5758 const file = await loadFile ( DATABINDING ) ;
58- const vm = await file . viewModelByNameAsync ( 'Person' ) ;
59+ const vm = file . viewModelByName ( 'Person' ) ;
5960 expectDefined ( vm ) ;
6061
6162 try {
@@ -68,7 +69,7 @@ describe('Async ViewModel Creation', () => {
6869
6970 it ( 'createBlankInstanceAsync returns an instance' , async ( ) => {
7071 const file = await loadFile ( DATABINDING ) ;
71- const vm = await file . viewModelByNameAsync ( 'Person' ) ;
72+ const vm = file . viewModelByName ( 'Person' ) ;
7273 expectDefined ( vm ) ;
7374
7475 const instance = await vm . createBlankInstanceAsync ( ) ;
@@ -108,7 +109,7 @@ describe('Async RiveFile Methods', () => {
108109describe ( 'Async ViewModel Metadata' , ( ) => {
109110 it ( 'getPropertiesAsync on ViewModel returns property info' , async ( ) => {
110111 const file = await loadFile ( DATABINDING ) ;
111- const vm = await file . viewModelByNameAsync ( 'Person' ) ;
112+ const vm = file . viewModelByName ( 'Person' ) ;
112113 expectDefined ( vm ) ;
113114
114115 try {
@@ -125,7 +126,7 @@ describe('Async ViewModel Metadata', () => {
125126
126127 it ( 'getPropertyCountAsync matches getPropertiesAsync length' , async ( ) => {
127128 const file = await loadFile ( DATABINDING ) ;
128- const vm = await file . viewModelByNameAsync ( 'Person' ) ;
129+ const vm = file . viewModelByName ( 'Person' ) ;
129130 expectDefined ( vm ) ;
130131
131132 try {
@@ -139,7 +140,7 @@ describe('Async ViewModel Metadata', () => {
139140
140141 it ( 'getInstanceCountAsync returns a non-negative number' , async ( ) => {
141142 const file = await loadFile ( DATABINDING ) ;
142- const vm = await file . viewModelByNameAsync ( 'Person' ) ;
143+ const vm = file . viewModelByName ( 'Person' ) ;
143144 expectDefined ( vm ) ;
144145
145146 const count = await vm . getInstanceCountAsync ( ) ;
@@ -149,7 +150,7 @@ describe('Async ViewModel Metadata', () => {
149150
150151describe ( 'Async Property getValueAsync' , ( ) => {
151152 it ( 'numberProperty getValueAsync returns correct value' , async ( ) => {
152- const instance = await createGordonInstanceAsync ( ) ;
153+ const instance = createGordonInstance ( await loadFile ( DATABINDING ) ) ;
153154 const prop = instance . numberProperty ( 'age' ) ;
154155 expectDefined ( prop ) ;
155156
@@ -158,7 +159,7 @@ describe('Async Property getValueAsync', () => {
158159 } ) ;
159160
160161 it ( 'stringProperty getValueAsync returns correct value' , async ( ) => {
161- const instance = await createGordonInstanceAsync ( ) ;
162+ const instance = createGordonInstance ( await loadFile ( DATABINDING ) ) ;
162163 const prop = instance . stringProperty ( 'name' ) ;
163164 expectDefined ( prop ) ;
164165
@@ -167,7 +168,7 @@ describe('Async Property getValueAsync', () => {
167168 } ) ;
168169
169170 it ( 'booleanProperty getValueAsync returns correct value' , async ( ) => {
170- const instance = await createGordonInstanceAsync ( ) ;
171+ const instance = createGordonInstance ( await loadFile ( DATABINDING ) ) ;
171172 const prop = instance . booleanProperty ( 'likes_popcorn' ) ;
172173 expectDefined ( prop ) ;
173174
@@ -176,7 +177,7 @@ describe('Async Property getValueAsync', () => {
176177 } ) ;
177178
178179 it ( 'colorProperty getValueAsync returns an ARGB number' , async ( ) => {
179- const instance = await createGordonInstanceAsync ( ) ;
180+ const instance = createGordonInstance ( await loadFile ( DATABINDING ) ) ;
180181 const prop = instance . colorProperty ( 'favourite_color' ) ;
181182 expectDefined ( prop ) ;
182183
@@ -187,7 +188,7 @@ describe('Async Property getValueAsync', () => {
187188 } ) ;
188189
189190 it ( 'enumProperty getValueAsync returns correct string' , async ( ) => {
190- const instance = await createGordonInstanceAsync ( ) ;
191+ const instance = createGordonInstance ( await loadFile ( DATABINDING ) ) ;
191192 const prop = instance . enumProperty ( 'favourite_pet' ) ;
192193 expectDefined ( prop ) ;
193194
@@ -196,7 +197,7 @@ describe('Async Property getValueAsync', () => {
196197 } ) ;
197198
198199 it ( 'set() then getValueAsync reflects the change for number' , async ( ) => {
199- const instance = await createGordonInstanceAsync ( ) ;
200+ const instance = createGordonInstance ( await loadFile ( DATABINDING ) ) ;
200201 const prop = instance . numberProperty ( 'age' ) ;
201202 expectDefined ( prop ) ;
202203
@@ -208,7 +209,7 @@ describe('Async Property getValueAsync', () => {
208209 } ) ;
209210
210211 it ( 'set() then getValueAsync reflects the change for string' , async ( ) => {
211- const instance = await createGordonInstanceAsync ( ) ;
212+ const instance = createGordonInstance ( await loadFile ( DATABINDING ) ) ;
212213 const prop = instance . stringProperty ( 'name' ) ;
213214 expectDefined ( prop ) ;
214215
@@ -219,7 +220,7 @@ describe('Async Property getValueAsync', () => {
219220 } ) ;
220221
221222 it ( 'set() then getValueAsync reflects the change for boolean' , async ( ) => {
222- const instance = await createGordonInstanceAsync ( ) ;
223+ const instance = createGordonInstance ( await loadFile ( DATABINDING ) ) ;
223224 const prop = instance . booleanProperty ( 'likes_popcorn' ) ;
224225 expectDefined ( prop ) ;
225226
@@ -230,7 +231,7 @@ describe('Async Property getValueAsync', () => {
230231 } ) ;
231232
232233 it ( 'set() then getValueAsync reflects the change for color' , async ( ) => {
233- const instance = await createGordonInstanceAsync ( ) ;
234+ const instance = createGordonInstance ( await loadFile ( DATABINDING ) ) ;
234235 const prop = instance . colorProperty ( 'favourite_color' ) ;
235236 expectDefined ( prop ) ;
236237
@@ -242,7 +243,7 @@ describe('Async Property getValueAsync', () => {
242243 } ) ;
243244
244245 it ( 'set() then getValueAsync reflects the change for enum' , async ( ) => {
245- const instance = await createGordonInstanceAsync ( ) ;
246+ const instance = createGordonInstance ( await loadFile ( DATABINDING ) ) ;
246247 const prop = instance . enumProperty ( 'favourite_pet' ) ;
247248 expectDefined ( prop ) ;
248249
@@ -255,7 +256,7 @@ describe('Async Property getValueAsync', () => {
255256
256257describe ( 'Async ViewModelInstance Methods' , ( ) => {
257258 it ( 'viewModelAsync returns nested instance' , async ( ) => {
258- const instance = await createGordonInstanceAsync ( ) ;
259+ const instance = createGordonInstance ( await loadFile ( DATABINDING ) ) ;
259260 const petInstance = await instance . viewModelAsync ( 'pet' ) ;
260261 expectDefined ( petInstance ) ;
261262
@@ -266,7 +267,7 @@ describe('Async ViewModelInstance Methods', () => {
266267 } ) ;
267268
268269 it ( 'viewModelAsync with non-existent path returns undefined or throws' , async ( ) => {
269- const instance = await createGordonInstanceAsync ( ) ;
270+ const instance = createGordonInstance ( await loadFile ( DATABINDING ) ) ;
270271 try {
271272 const result = await instance . viewModelAsync ( 'nonexistent' ) ;
272273 // Legacy returns undefined, experimental may return a wrapper or throw
@@ -280,10 +281,7 @@ describe('Async ViewModelInstance Methods', () => {
280281
281282 it ( 'getPropertiesAsync on ViewModelInstance returns property info' , async ( ) => {
282283 const file = await loadFile ( DATABINDING ) ;
283- const vm = await file . viewModelByNameAsync ( 'Person' ) ;
284- expectDefined ( vm ) ;
285- const instance = await vm . createInstanceByNameAsync ( 'Gordon' ) ;
286- expectDefined ( instance ) ;
284+ const instance = createGordonInstance ( file ) ;
287285
288286 try {
289287 const props = await instance . getPropertiesAsync ( ) ;
@@ -300,9 +298,9 @@ describe('Async ViewModelInstance Methods', () => {
300298describe ( 'Async List Operations' , ( ) => {
301299 async function createDevRelInstance ( ) {
302300 const file = await loadFile ( DATABINDING_LISTS ) ;
303- const vm = await file . viewModelByNameAsync ( 'DevRel' ) ;
301+ const vm = file . viewModelByName ( 'DevRel' ) ;
304302 expectDefined ( vm ) ;
305- const instance = await vm . createDefaultInstanceAsync ( ) ;
303+ const instance = vm . createDefaultInstance ( ) ;
306304 expectDefined ( instance ) ;
307305 return { file, instance } ;
308306 }
@@ -337,9 +335,9 @@ describe('Async List Operations', () => {
337335
338336 const initialLength = await list . getLengthAsync ( ) ;
339337
340- const personVM = await file . viewModelByNameAsync ( 'Person' ) ;
338+ const personVM = file . viewModelByName ( 'Person' ) ;
341339 expectDefined ( personVM ) ;
342- const newPerson = await personVM . createBlankInstanceAsync ( ) ;
340+ const newPerson = personVM . createInstance ( ) ;
343341 expectDefined ( newPerson ) ;
344342 const nameProp = newPerson . stringProperty ( 'name' ) ;
345343 expectDefined ( nameProp ) ;
0 commit comments