mediawiki-extensions-Visual.../modules/ve/ve.Registry.js
Trevor Parscal 8d33a3de0d Major Documentation Cleanup
* Made method descriptions imperative: "Do this" rather than "Does this"
* Changed use of "this object" to "the object" in method documentation
* Added missing documentation
* Fixed incorrect documentation
* Fixed incorrect debug method names (as in those VeDmClassName tags we add to functions so they make sense when dumped into in the console)
* Normalized use of package names throughout
* Normalized class descriptions
* Removed incorrect @abstract tags
* Added missing @method tags
* Lots of other minor cleanup

Change-Id: I4ea66a2dd107613e2ea3a5f56ff54d675d72957e
2013-01-16 15:37:59 -08:00

64 lines
1.5 KiB
JavaScript

/*!
* VisualEditor Registry class.
*
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Generic data registry.
*
* @abstract
* @extends ve.EventEmitter
* @constructor
*/
ve.Registry = function VeRegistry() {
// Parent constructor
ve.EventEmitter.call( this );
// Properties
this.registry = {};
};
/* Inheritance */
ve.inheritClass( ve.Registry, ve.EventEmitter );
/* Methods */
/**
* Associate one or more symbolic names with some data.
*
* @method
* @param {string|string[]} name Symbolic name or list of symbolic names
* @param {Mixed} data Data to associate with symbolic name
* @throws {Error} Name argument must be a string or array
*/
ve.Registry.prototype.register = function ( name, data ) {
if ( typeof name !== 'string' && !ve.isArray( name ) ) {
throw new Error( 'Name argument must be a string or array, cannot be a ' + typeof name );
}
var i, len;
if ( ve.isArray( name ) ) {
for ( i = 0, len = name.length; i < len; i++ ) {
this.register( name[i], data );
}
} else if ( typeof name === 'string' ) {
this.registry[name] = data;
this.emit( 'register', name, data );
} else {
throw new Error( 'Name must be a string or array of strings, cannot be a ' + typeof name );
}
};
/**
* Gets data for a given symbolic name.
*
* @method
* @param {string} name Symbolic name
* @returns {Mixed|undefined} Data associated with symbolic name
*/
ve.Registry.prototype.lookup = function ( name ) {
return this.registry[name];
};