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

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                            1x   7x         1x                       1x 15462x 15462x        
/*!
 * VisualEditor DataModel ModelFactory class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * 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 {...any} [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, ...args ) {
	Eif ( element && element.type ) {
		return this.create( element.type, element, ...args );
	}
	throw new Error( 'Element must have a .type property' );
};