all files / model/ NodeRegistry.js

55.56% Statements 5/9
62.5% Branches 5/8
100% Functions 1/1
55.56% Lines 5/9
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                              8349× 8349×       8349×     8349×     8349×            
import { Registry } from '../util'
 
/*
  Registry for Nodes.
 
  @class NodeRegistry
  @extends util/Registry
 */
class NodeRegistry extends Registry {
  /**
    Register a Node class.
 
    @param {Class} nodeClass
   */
  register(nodeClazz) {
    var type = nodeClazz.prototype.type
    Iif ( typeof type !== 'string' || type === '' ) {
      console.error('#### nodeClazz', nodeClazz)
      throw new Error( 'Node names must be strings and must not be empty')
    }
    Iif ( !( nodeClazz.prototype._isNode) ) {
      throw new Error( 'Nodes must be subclasses of Substance.Data.Node' )
    }
    Iif (this.contains(type)) {
      throw new Error('Node class is already registered: ' + type)
    }
    this.add(type, nodeClazz)
  }
 
}
 
export default NodeRegistry