mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
Merge "Convert AnnotationFactory and MetaItemFactory to NamedClassFactories"
This commit is contained in:
commit
05f4579a53
|
@ -9,17 +9,17 @@
|
|||
* DataModel annotation factory.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.Factory
|
||||
* @extends ve.NamedClassFactory
|
||||
* @constructor
|
||||
*/
|
||||
ve.dm.AnnotationFactory = function VeDmAnnotationFactory() {
|
||||
// Parent constructor
|
||||
ve.Factory.call( this );
|
||||
ve.NamedClassFactory.call( this );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
ve.inheritClass( ve.dm.AnnotationFactory, ve.Factory );
|
||||
ve.inheritClass( ve.dm.AnnotationFactory, ve.NamedClassFactory );
|
||||
|
||||
/* Initialization */
|
||||
|
||||
|
|
|
@ -9,17 +9,17 @@
|
|||
* DataModel meta item factory.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.Factory
|
||||
* @extends ve.NamedClassFactory
|
||||
* @constructor
|
||||
*/
|
||||
ve.dm.MetaItemFactory = function VeDmMetaItemFactory() {
|
||||
// Parent constructor
|
||||
ve.Factory.call( this );
|
||||
ve.NamedClassFactory.call( this );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
ve.inheritClass( ve.dm.MetaItemFactory, ve.Factory );
|
||||
ve.inheritClass( ve.dm.MetaItemFactory, ve.NamedClassFactory );
|
||||
|
||||
/* Methods */
|
||||
|
||||
|
|
|
@ -71,22 +71,27 @@ function addType( obj /*, ...*/ ) {
|
|||
* Register a model type.
|
||||
* @param {string} name Symbolic name for the model
|
||||
* @param {ve.dm.Model} constructor Subclass of ve.dm.Model
|
||||
* @throws Models must be subclasses of ve.dm.Model
|
||||
* @throws No factory associated with this ve.dm.Model subclass
|
||||
*/
|
||||
ve.dm.ModelRegistry.prototype.register = function ( constructor ) {
|
||||
var i, j, tags, types, name = constructor.static && constructor.static.name;
|
||||
if ( typeof name !== 'string' || name === '' ) {
|
||||
throw new Error( 'Model names must be strings and must not be empty' );
|
||||
}
|
||||
if ( !( constructor.prototype instanceof ve.dm.Model ) ) {
|
||||
throw new Error( 'Models must be subclasses of ve.dm.Model' );
|
||||
}
|
||||
|
||||
// Register the model with the right factory
|
||||
if ( constructor.prototype instanceof ve.dm.Annotation ) {
|
||||
ve.dm.annotationFactory.register( name, constructor );
|
||||
ve.dm.annotationFactory.register( constructor );
|
||||
} else if ( constructor.prototype instanceof ve.dm.Node ) {
|
||||
ve.dm.nodeFactory.register( constructor );
|
||||
} else if ( constructor.prototype instanceof ve.dm.MetaItem ) {
|
||||
ve.dm.metaItemFactory.register( name, constructor );
|
||||
ve.dm.metaItemFactory.register( constructor );
|
||||
} else {
|
||||
throw new Error( 'Models must be subclasses of ve.dm.Annotation, ve.dm.Node or ve.dm.MetaItem' );
|
||||
throw new Error( 'No factory associated with this ve.dm.Model subclass' );
|
||||
}
|
||||
// Call parent implementation
|
||||
ve.Registry.prototype.register.call( this, name, constructor );
|
||||
|
|
Loading…
Reference in a new issue