all files / src/dm/ ve.dm.ModelFactory.js

85.71% Statements 6/7
75% Branches 3/4
100% Functions 2/2
85.71% Lines 6/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40                                                            12266× 12266×        
/*!
 * VisualEditor DataModel ModelFactory class.
 *
 * @copyright 2011-2019 VisualEditor Team and others; see http://ve.mit-license.org
 */
 
/**
 * DataModel meta item factory.
 *
 * @class
 * @abstract
 * @extends OO.Factory
 * @constructor
 */
ve.dm.ModelFactory = function VeDmModelFactory() {
	// Parent constructor
	ve.dm.ModelFactory.super.call( this );
};
 
/* Inheritance */
 
OO.inheritClass( ve.dm.ModelFactory, OO.Factory );
 
/* Methods */
 
/**
 * Create a new item from a model element
 *
 * @param {Object} element Model element
 * @param {...Mixed} [args] Arguments to pass to the constructor
 * @return {ve.dm.Model} Model constructed from element
 * @throws {Error} Element must have a .type property
 */
ve.dm.ModelFactory.prototype.createFromElement = function ( element ) {
	Eif ( element && element.type ) {
		return this.create.apply( this, Array.prototype.concat.apply( [ element.type ], arguments ) );
	}
	throw new Error( 'Element must have a .type property' );
};