Browse Source

AnimationObjectGroup: Convert to es6 class

Ian Purvis 5 years ago
parent
commit
f5eb8197f5
1 changed files with 42 additions and 43 deletions
  1. 42 43
      src/animation/AnimationObjectGroup.js

+ 42 - 43
src/animation/AnimationObjectGroup.js

@@ -30,61 +30,59 @@ import { MathUtils } from '../math/MathUtils.js';
  *    target group or directly, but not both.
  */
 
-function AnimationObjectGroup() {
+class AnimationObjectGroup {
 
-	this.uuid = MathUtils.generateUUID();
+	constructor() {
 
-	// cached objects followed by the active ones
-	this._objects = Array.prototype.slice.call( arguments );
+		this.uuid = MathUtils.generateUUID();
 
-	this.nCachedObjects_ = 0; // threshold
-	// note: read by PropertyBinding.Composite
+		// cached objects followed by the active ones
+		this._objects = Array.prototype.slice.call( arguments );
 
-	const indices = {};
-	this._indicesByUUID = indices; // for bookkeeping
+		this.nCachedObjects_ = 0; // threshold
+		// note: read by PropertyBinding.Composite
 
-	for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
+		const indices = {};
+		this._indicesByUUID = indices; // for bookkeeping
 
-		indices[ arguments[ i ].uuid ] = i;
+		for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
 
-	}
+			indices[ arguments[ i ].uuid ] = i;
 
-	this._paths = []; // inside: string
-	this._parsedPaths = []; // inside: { we don't care, here }
-	this._bindings = []; // inside: Array< PropertyBinding >
-	this._bindingsIndicesByPath = {}; // inside: indices in these arrays
+		}
 
-	const scope = this;
+		this._paths = []; // inside: string
+		this._parsedPaths = []; // inside: { we don't care, here }
+		this._bindings = []; // inside: Array< PropertyBinding >
+		this._bindingsIndicesByPath = {}; // inside: indices in these arrays
 
-	this.stats = {
+		const scope = this;
 
-		objects: {
-			get total() {
+		this.stats = {
 
-				return scope._objects.length;
+			objects: {
+				get total() {
 
-			},
-			get inUse() {
+					return scope._objects.length;
 
-				return this.total - scope.nCachedObjects_;
+				},
+				get inUse() {
 
-			}
-		},
-		get bindingsPerObject() {
+					return this.total - scope.nCachedObjects_;
 
-			return scope._bindings.length;
-
-		}
+				}
+			},
+			get bindingsPerObject() {
 
-	};
+				return scope._bindings.length;
 
-}
+			}
 
-Object.assign( AnimationObjectGroup.prototype, {
+		};
 
-	isAnimationObjectGroup: true,
+	}
 
-	add: function () {
+	add() {
 
 		const objects = this._objects,
 			indicesByUUID = this._indicesByUUID,
@@ -170,9 +168,9 @@ Object.assign( AnimationObjectGroup.prototype, {
 
 		this.nCachedObjects_ = nCachedObjects;
 
-	},
+	}
 
-	remove: function () {
+	remove() {
 
 		const objects = this._objects,
 			indicesByUUID = this._indicesByUUID,
@@ -219,10 +217,10 @@ Object.assign( AnimationObjectGroup.prototype, {
 
 		this.nCachedObjects_ = nCachedObjects;
 
-	},
+	}
 
 	// remove & forget
-	uncache: function () {
+	uncache() {
 
 		const objects = this._objects,
 			indicesByUUID = this._indicesByUUID,
@@ -309,11 +307,11 @@ Object.assign( AnimationObjectGroup.prototype, {
 
 		this.nCachedObjects_ = nCachedObjects;
 
-	},
+	}
 
 	// Internal interface used by befriended PropertyBinding.Composite:
 
-	subscribe_: function ( path, parsedPath ) {
+	subscribe_( path, parsedPath ) {
 
 		// returns an array of bindings for the given path that is changed
 		// according to the contained objects in the group
@@ -348,9 +346,9 @@ Object.assign( AnimationObjectGroup.prototype, {
 
 		return bindingsForPath;
 
-	},
+	}
 
-	unsubscribe_: function ( path ) {
+	unsubscribe_( path ) {
 
 		// tells the group to forget about a property path and no longer
 		// update the array previously obtained with 'subscribe_'
@@ -382,7 +380,8 @@ Object.assign( AnimationObjectGroup.prototype, {
 
 	}
 
-} );
+}
 
+AnimationObjectGroup.prototype.isAnimationObjectGroup = true;
 
 export { AnimationObjectGroup };