2013-03-06 22:44:18 +00:00
|
|
|
/*!
|
2013-04-02 18:40:06 +00:00
|
|
|
* VisualEditor NamedClassFactory class.
|
2013-03-06 22:44:18 +00:00
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-04-02 18:40:06 +00:00
|
|
|
* Generic factory for classes with a .static.name property.
|
2013-03-06 22:44:18 +00:00
|
|
|
*
|
|
|
|
* @abstract
|
|
|
|
* @extends ve.Factory
|
|
|
|
* @constructor
|
|
|
|
*/
|
2013-04-02 18:40:06 +00:00
|
|
|
ve.NamedClassFactory = function VeNamedClassFactory() {
|
2013-03-06 22:44:18 +00:00
|
|
|
// Parent constructor
|
|
|
|
ve.Factory.call( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-04-02 18:40:06 +00:00
|
|
|
ve.inheritClass( ve.NamedClassFactory, ve.Factory );
|
2013-03-06 22:44:18 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a constructor with the factory.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Function} constructor Constructor to use when creating object
|
2013-04-02 18:40:06 +00:00
|
|
|
* @throws {Error} Names must be strings and must not be empty
|
2013-03-06 22:44:18 +00:00
|
|
|
*/
|
2013-04-02 18:40:06 +00:00
|
|
|
ve.NamedClassFactory.prototype.register = function ( constructor ) {
|
2013-03-06 22:44:18 +00:00
|
|
|
var name = constructor.static && constructor.static.name;
|
|
|
|
if ( typeof name !== 'string' || name === '' ) {
|
2013-04-02 18:40:06 +00:00
|
|
|
throw new Error( 'Names must be strings and must not be empty' );
|
2013-03-06 22:44:18 +00:00
|
|
|
}
|
|
|
|
ve.Factory.prototype.register.call( this, name, constructor );
|
|
|
|
};
|