Skip to content

Instantly share code, notes, and snippets.

@cojack
Created April 30, 2014 13:16
Show Gist options
  • Save cojack/bd909f136cd0a2b32d2a to your computer and use it in GitHub Desktop.
Save cojack/bd909f136cd0a2b32d2a to your computer and use it in GitHub Desktop.
(function() {
'use strict';
var HashMap = require('./utils/HashMap');
/**
*
* @static
* @class ComponentType
*/
var ComponentType = function ComponentType() {
/**
* @private
* @property type
* @type {ArtemiJS.Component}
*/
var type,
/**
* @private
* @static
* @property INDEX
* @type {Number}
*/
INDEX = 0,
/**
* @private
* @property index
* @type {Number}
*/
index,
/**
*
*
*/
componentTypes = new HashMap();
/**
*
*
*/
function Constructor(_type) {
this.index = INDEX++;
this.type = _type;
}
return {
index: 0,
type: null,
getIndex: function() {
return this.index;
},
/**
*
*
*/
getTypeFor: function(component) {
var _type = componentTypes.get(component);
if(!_type) {
_type = new ComponentType(_type);
componentTypes.put(component, _type);
}
return _type;
},
/**
*
*/
getIndexFor: function(component) {
return this.getTypeFor(component).getIndex();
},
toString: function() {
return "ComponentType["+type.getSimpleName()+"] ("+index+")";
}
};
};
module.exports = ComponentType;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment