Expand all

ve.dm.ModelRegistry

Extends

Constructor

new ve.dm.ModelRegistry() #

Registry for models.

To register a new model type, call #register.

Source:
Registry for models.

Methods

isAnnotation(node) → {boolean} #

Tests whether a node will be modelled as an annotation

Parameters:

Name Type Description
node Node

The node

Source:

Returns:

Whether the element will be modelled as an annotation

Type
boolean
Tests whether a node will be modelled as an annotation

matchElement(node, [forceAboutGrouping], [excludeTypes]) → {string|null} #

Determine which model best matches the given node

Model matching works as follows:

Get all models whose tag and rdfaType rules match

Rank them in order of specificity:

  • tag, rdfaType and func specified
  • rdfaType and func specified
  • tag and func specified
  • func specified
  • tag and rdfaType specified
  • rdfaType specified
  • tag specified
  • nothing specified

If there are multiple candidates with the same specificity, exact matches of strings take precedence over matches of regular expressions. If there are still multiple candidates, they are ranked in reverse order of registration (i.e. if A was registered before B, B will rank above A). The highest-ranking model whose test function does not return false, wins.

Parameters:

Name Type Attributes Description
node Node

Node to match (usually an HTMLElement but can also be a Comment node)

forceAboutGrouping boolean optional

If true, only match models with about grouping enabled

excludeTypes Array.<string> optional

Model names to exclude when matching

Source:

Returns:

Model type, or null if none found

Type
string | null

Determine which model best matches the given node

Model matching works as follows:

Get all models whose tag and rdfaType rules match

Rank them in order of specificity:

  • tag, rdfaType and func specified
  • rdfaType and func specified
  • tag and func specified
  • func specified
  • tag and rdfaType specified
  • rdfaType specified
  • tag specified
  • nothing specified

If there are multiple candidates with the same specificity, exact matches of strings take precedence over matches of regular expressions.

register(constructor) #

Register a model type.

Parameters:

Name Type Description
constructor ve.dm.Model

Subclass of ve.dm.Model

Source:

Throws:

  • Model names must be strings and must not be empty

  • Models must be subclasses of ve.dm.Model

  • No factory associated with this ve.dm.Model subclass

Register a model type.

unregister(constructor) #

Unregister a model type.

Parameters:

Name Type Description
constructor ve.dm.Model

Subclass of ve.dm.Model

Source:

Throws:

  • Model names must be strings and must not be empty

  • Models must be subclasses of ve.dm.Model

  • No factory associated with this ve.dm.Model subclass

Unregister a model type.