Skip to content

Commit 2a2a8a5

Browse files
authored
Loaders: Convert to ES6. (#21622)
1 parent 80317f2 commit 2a2a8a5

File tree

8 files changed

+145
-152
lines changed

8 files changed

+145
-152
lines changed

src/loaders/CompressedTextureLoader.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ import { Loader } from './Loader.js';
99
* Sub classes have to implement the parse() method which will be used in load().
1010
*/
1111

12-
function CompressedTextureLoader( manager ) {
12+
class CompressedTextureLoader extends Loader {
1313

14-
Loader.call( this, manager );
14+
constructor( manager ) {
1515

16-
}
17-
18-
CompressedTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
16+
super( manager );
1917

20-
constructor: CompressedTextureLoader,
18+
}
2119

22-
load: function ( url, onLoad, onProgress, onError ) {
20+
load( url, onLoad, onProgress, onError ) {
2321

2422
const scope = this;
2523

@@ -130,7 +128,7 @@ CompressedTextureLoader.prototype = Object.assign( Object.create( Loader.prototy
130128

131129
}
132130

133-
} );
131+
}
134132

135133

136134
export { CompressedTextureLoader };

src/loaders/DataTextureLoader.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ import { Loader } from './Loader.js';
99
* Sub classes have to implement the parse() method which will be used in load().
1010
*/
1111

12-
function DataTextureLoader( manager ) {
12+
class DataTextureLoader extends Loader {
1313

14-
Loader.call( this, manager );
14+
constructor( manager ) {
1515

16-
}
17-
18-
DataTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
16+
super( manager );
1917

20-
constructor: DataTextureLoader,
18+
}
2119

22-
load: function ( url, onLoad, onProgress, onError ) {
20+
load( url, onLoad, onProgress, onError ) {
2321

2422
const scope = this;
2523

@@ -110,7 +108,7 @@ DataTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ),
110108

111109
}
112110

113-
} );
111+
}
114112

115113

116114
export { DataTextureLoader };

src/loaders/FileLoader.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ import { Loader } from './Loader.js';
33

44
const loading = {};
55

6-
function FileLoader( manager ) {
6+
class FileLoader extends Loader {
77

8-
Loader.call( this, manager );
8+
constructor( manager ) {
99

10-
}
11-
12-
FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
10+
super( manager );
1311

14-
constructor: FileLoader,
12+
}
1513

16-
load: function ( url, onLoad, onProgress, onError ) {
14+
load( url, onLoad, onProgress, onError ) {
1715

1816
if ( url === undefined ) url = '';
1917

@@ -277,23 +275,23 @@ FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
277275

278276
return request;
279277

280-
},
278+
}
281279

282-
setResponseType: function ( value ) {
280+
setResponseType( value ) {
283281

284282
this.responseType = value;
285283
return this;
286284

287-
},
285+
}
288286

289-
setMimeType: function ( value ) {
287+
setMimeType( value ) {
290288

291289
this.mimeType = value;
292290
return this;
293291

294292
}
295293

296-
} );
294+
}
297295

298296

299297
export { FileLoader };

src/loaders/ImageBitmapLoader.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
11
import { Cache } from './Cache.js';
22
import { Loader } from './Loader.js';
33

4-
function ImageBitmapLoader( manager ) {
4+
class ImageBitmapLoader extends Loader {
55

6-
if ( typeof createImageBitmap === 'undefined' ) {
6+
constructor( manager ) {
77

8-
console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
8+
super( manager );
99

10-
}
11-
12-
if ( typeof fetch === 'undefined' ) {
13-
14-
console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
10+
if ( typeof createImageBitmap === 'undefined' ) {
1511

16-
}
12+
console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
1713

18-
Loader.call( this, manager );
14+
}
1915

20-
this.options = { premultiplyAlpha: 'none' };
16+
if ( typeof fetch === 'undefined' ) {
2117

22-
}
18+
console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
2319

24-
ImageBitmapLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
20+
}
2521

26-
constructor: ImageBitmapLoader,
22+
this.options = { premultiplyAlpha: 'none' };
2723

28-
isImageBitmapLoader: true,
24+
}
2925

30-
setOptions: function setOptions( options ) {
26+
setOptions( options ) {
3127

3228
this.options = options;
3329

3430
return this;
3531

36-
},
32+
}
3733

38-
load: function ( url, onLoad, onProgress, onError ) {
34+
load( url, onLoad, onProgress, onError ) {
3935

4036
if ( url === undefined ) url = '';
4137

@@ -96,6 +92,8 @@ ImageBitmapLoader.prototype = Object.assign( Object.create( Loader.prototype ),
9692

9793
}
9894

99-
} );
95+
}
96+
97+
ImageBitmapLoader.prototype.isImageBitmapLoader = true;
10098

10199
export { ImageBitmapLoader };

src/loaders/Loader.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import { DefaultLoadingManager } from './LoadingManager.js';
22

3-
function Loader( manager ) {
3+
class Loader {
44

5-
this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
5+
constructor( manager ) {
66

7-
this.crossOrigin = 'anonymous';
8-
this.withCredentials = false;
9-
this.path = '';
10-
this.resourcePath = '';
11-
this.requestHeader = {};
7+
this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
128

13-
}
9+
this.crossOrigin = 'anonymous';
10+
this.withCredentials = false;
11+
this.path = '';
12+
this.resourcePath = '';
13+
this.requestHeader = {};
1414

15-
Object.assign( Loader.prototype, {
15+
}
1616

17-
load: function ( /* url, onLoad, onProgress, onError */ ) {},
17+
load( /* url, onLoad, onProgress, onError */ ) {}
1818

19-
loadAsync: function ( url, onProgress ) {
19+
loadAsync( url, onProgress ) {
2020

2121
const scope = this;
2222

@@ -26,45 +26,45 @@ Object.assign( Loader.prototype, {
2626

2727
} );
2828

29-
},
29+
}
3030

31-
parse: function ( /* data */ ) {},
31+
parse( /* data */ ) {}
3232

33-
setCrossOrigin: function ( crossOrigin ) {
33+
setCrossOrigin( crossOrigin ) {
3434

3535
this.crossOrigin = crossOrigin;
3636
return this;
3737

38-
},
38+
}
3939

40-
setWithCredentials: function ( value ) {
40+
setWithCredentials( value ) {
4141

4242
this.withCredentials = value;
4343
return this;
4444

45-
},
45+
}
4646

47-
setPath: function ( path ) {
47+
setPath( path ) {
4848

4949
this.path = path;
5050
return this;
5151

52-
},
52+
}
5353

54-
setResourcePath: function ( resourcePath ) {
54+
setResourcePath( resourcePath ) {
5555

5656
this.resourcePath = resourcePath;
5757
return this;
5858

59-
},
59+
}
6060

61-
setRequestHeader: function ( requestHeader ) {
61+
setRequestHeader( requestHeader ) {
6262

6363
this.requestHeader = requestHeader;
6464
return this;
6565

6666
}
6767

68-
} );
68+
}
6969

7070
export { Loader };

src/loaders/LoaderUtils.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const LoaderUtils = {
1+
class LoaderUtils {
22

3-
decodeText: function ( array ) {
3+
static decodeText( array ) {
44

55
if ( typeof TextDecoder !== 'undefined' ) {
66

@@ -32,9 +32,9 @@ const LoaderUtils = {
3232

3333
}
3434

35-
},
35+
}
3636

37-
extractUrlBase: function ( url ) {
37+
static extractUrlBase( url ) {
3838

3939
const index = url.lastIndexOf( '/' );
4040

@@ -44,6 +44,6 @@ const LoaderUtils = {
4444

4545
}
4646

47-
};
47+
}
4848

4949
export { LoaderUtils };

0 commit comments

Comments
 (0)