Skip to content

Commit ed8831b

Browse files
tschwmrdoob
authored andcommitted
EventDispatcher: Deprecated .apply. (mrdoob#8775)
* EventDispatcher: Deprecated .apply. * EventDispatcher: Removed unit test for .apply.
1 parent cd5b6bd commit ed8831b

File tree

17 files changed

+52
-84
lines changed

17 files changed

+52
-84
lines changed

examples/js/loaders/MTLLoader.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ THREE.MTLLoader = function( manager ) {
1010

1111
};
1212

13-
THREE.MTLLoader.prototype = {
14-
15-
constructor: THREE.MTLLoader,
13+
Object.assign( THREE.MTLLoader.prototype, THREE.EventDispatcher.prototype, {
1614

1715
/**
1816
* Loads and parses a MTL asset from a URL.
@@ -167,7 +165,7 @@ THREE.MTLLoader.prototype = {
167165

168166
}
169167

170-
};
168+
} );
171169

172170
/**
173171
* Create a new THREE-MTLLoader.MaterialCreator
@@ -476,5 +474,3 @@ THREE.MTLLoader.MaterialCreator.prototype = {
476474
}
477475

478476
};
479-
480-
THREE.EventDispatcher.prototype.apply( THREE.MTLLoader.prototype );

examples/js/loaders/NRRDLoader.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ THREE.NRRDLoader = function( manager ) {
55

66
};
77

8-
THREE.NRRDLoader.prototype = {
9-
10-
constructor: THREE.NRRDLoader,
8+
Object.assign( THREE.NRRDLoader.prototype, THREE.EventDispatcher.prototype, {
119

1210
load: function( url, onLoad, onProgress, onError ) {
1311

@@ -586,6 +584,4 @@ THREE.NRRDLoader.prototype = {
586584
}
587585
}
588586

589-
};
590-
591-
THREE.EventDispatcher.prototype.apply( THREE.NRRDLoader.prototype );
587+
} );

examples/js/loaders/PCDLoader.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ THREE.PCDLoader = function( manager ) {
1313
this.littleEndian = true;
1414

1515
};
16-
THREE.PCDLoader.prototype = {
1716

18-
constructor: THREE.PCDLoader,
17+
18+
Object.assign( THREE.PCDLoader.prototype, THREE.EventDispatcher.prototype, {
1919

2020
load: function( url, onLoad, onProgress, onError ) {
2121

@@ -246,6 +246,4 @@ THREE.PCDLoader.prototype = {
246246

247247
},
248248

249-
};
250-
251-
THREE.EventDispatcher.prototype.apply( THREE.PCDLoader.prototype );
249+
} );

examples/js/loaders/VTKLoader.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ THREE.VTKLoader = function( manager ) {
99

1010
};
1111

12-
THREE.VTKLoader.prototype = {
13-
14-
constructor: THREE.VTKLoader,
12+
Object.assign( THREE.VTKLoader.prototype, THREE.EventDispatcher.prototype, {
1513

1614
load: function ( url, onLoad, onProgress, onError ) {
1715

@@ -1108,6 +1106,4 @@ THREE.VTKLoader.prototype = {
11081106

11091107
}
11101108

1111-
};
1112-
1113-
THREE.EventDispatcher.prototype.apply( THREE.VTKLoader.prototype );
1109+
} );

examples/js/renderers/RaytracingRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,4 @@ THREE.RaytracingRenderer = function ( parameters ) {
286286

287287
};
288288

289-
THREE.EventDispatcher.prototype.apply( THREE.RaytracingRenderer.prototype );
289+
Object.assign( THREE.RaytracingRenderer.prototype, THREE.EventDispatcher.prototype );

examples/js/renderers/RaytracingWorker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,4 +564,4 @@ THREE.RaytracingRendererWorker = function ( parameters ) {
564564

565565
};
566566

567-
THREE.EventDispatcher.prototype.apply( THREE.RaytracingRendererWorker.prototype );
567+
Object.assign( THREE.RaytracingRendererWorker.prototype, THREE.EventDispatcher.prototype );

src/animation/AnimationMixer.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ THREE.AnimationMixer = function( root ) {
2020

2121
};
2222

23-
THREE.AnimationMixer.prototype = {
24-
25-
constructor: THREE.AnimationMixer,
23+
Object.assign( THREE.AnimationMixer.prototype, THREE.EventDispatcher.prototype, {
2624

2725
// return an action for a clip optionally using a custom root target
2826
// object (this method allocates a lot of dynamic memory in case a
@@ -267,12 +265,10 @@ THREE.AnimationMixer.prototype = {
267265

268266
}
269267

270-
};
268+
} );
271269

272270
THREE.AnimationMixer._Action = THREE.AnimationAction._new;
273271

274-
THREE.EventDispatcher.prototype.apply( THREE.AnimationMixer.prototype );
275-
276272
// Implementation details:
277273

278274
Object.assign( THREE.AnimationMixer.prototype, {

src/core/BufferGeometry.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ THREE.BufferGeometry = function () {
2626

2727
};
2828

29-
THREE.BufferGeometry.prototype = {
30-
31-
constructor: THREE.BufferGeometry,
29+
Object.assign( THREE.BufferGeometry.prototype, THREE.EventDispatcher.prototype, {
3230

3331
getIndex: function () {
3432

@@ -1015,8 +1013,6 @@ THREE.BufferGeometry.prototype = {
10151013

10161014
}
10171015

1018-
};
1019-
1020-
THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
1016+
} );
10211017

10221018
THREE.BufferGeometry.MaxIndex = 65535;

src/core/DirectGeometry.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ THREE.DirectGeometry = function () {
4040

4141
};
4242

43-
THREE.DirectGeometry.prototype = {
44-
45-
constructor: THREE.DirectGeometry,
43+
Object.assign( THREE.DirectGeometry.prototype, THREE.EventDispatcher.prototype, {
4644

4745
computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
4846
computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
@@ -285,6 +283,4 @@ THREE.DirectGeometry.prototype = {
285283

286284
}
287285

288-
};
289-
290-
THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
286+
} );

src/core/EventDispatcher.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,39 @@
44

55
THREE.EventDispatcher = function () {};
66

7-
THREE.EventDispatcher.prototype = {
7+
//
8+
// [Deprecation]
9+
//
10+
11+
THREE.EventDispatcher.prototype = Object.assign( Object.create( {
812

913
constructor: THREE.EventDispatcher,
1014

1115
apply: function ( object ) {
1216

17+
console.warn( "THREE.EventDispatcher: .apply is deprecated, " +
18+
"just inherit or Object.assign the prototype to mix-in." );
19+
1320
object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
1421
object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
1522
object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
1623
object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
1724

18-
},
25+
}
26+
27+
// Notes:
28+
// - The prototype chain ensures that Object.assign will not copy the
29+
// properties within this block.
30+
// - When .constructor is not explicitly set, it is not copied either,
31+
// so use the disabled code below so doesn't need to be clobbered.
32+
33+
} ), {
34+
35+
//
36+
// [/Deprecation]
37+
//
38+
39+
//Object.assign( THREE.EventDispatcher.prototype, {
1940

2041
addEventListener: function ( type, listener ) {
2142

@@ -104,4 +125,4 @@ THREE.EventDispatcher.prototype = {
104125

105126
}
106127

107-
};
128+
} );

0 commit comments

Comments
 (0)