| 1 | /*! |
| 2 | * VisualEditor DataModel ModelFactory class. |
| 3 | * |
| 4 | * @copyright See AUTHORS.txt |
| 5 | */ |
| 6 | |
| 7 | /** |
| 8 | * DataModel meta item factory. |
| 9 | * |
| 10 | * @class |
| 11 | * @abstract |
| 12 | * @extends OO.Factory |
| 13 | * @constructor |
| 14 | */ |
| 15 | ve.dm.ModelFactory = function VeDmModelFactory() { |
| 16 | // Parent constructor |
| 17 | ve.dm.ModelFactory.super.call( this ); |
| 18 | }; |
| 19 | |
| 20 | /* Inheritance */ |
| 21 | |
| 22 | OO.inheritClass( ve.dm.ModelFactory, OO.Factory ); |
| 23 | |
| 24 | /* Methods */ |
| 25 | |
| 26 | /** |
| 27 | * Create a new item from a model element |
| 28 | * |
| 29 | * @param {Object} element Model element |
| 30 | * @param {...any} [args] Arguments to pass to the constructor |
| 31 | * @return {ve.dm.Model} Model constructed from element |
| 32 | * @throws {Error} Element must have a .type property |
| 33 | */ |
| 34 | ve.dm.ModelFactory.prototype.createFromElement = function ( element, ...args ) { |
| 35 | if ( element && element.type ) { |
| 36 | return this.create( element.type, element, ...args ); |
| 37 | } |
| 38 | throw new Error( 'Element must have a .type property' ); |
| 39 | }; |