Browse Source

Examples: Use async/await instead of promises.

Mr.doob 4 years ago
parent
commit
80509b14fe
1 changed files with 5 additions and 9 deletions
  1. 5 9
      examples/index.html

+ 5 - 9
examples/index.html

@@ -61,21 +61,17 @@
 
 
 		let selected = null;
 		let selected = null;
 
 
-		Promise.all( [
-			fetch( 'files.json' ).then( response => response.json() ),
-			fetch( 'tags.json' ).then( response => response.json() )
-		] ).then( ( json ) => {
+		init();
 
 
-			init( json[ 0 ], json[ 1 ] );
-
-		} );
-
-		function init( files, tags ) {
+		async function init() {
 
 
 			content.appendChild( container );
 			content.appendChild( container );
 
 
 			viewSrcButton.style.display = 'none';
 			viewSrcButton.style.display = 'none';
 
 
+			const files = await ( await fetch( 'files.json' ) ).json();
+			const tags = await ( await fetch( 'tags.json' ) ).json();
+
 			for ( const key in files ) {
 			for ( const key in files ) {
 
 
 				const section = files[ key ];
 				const section = files[ key ];