Created
April 30, 2014 13:16
-
-
Save cojack/bd909f136cd0a2b32d2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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