Skip to content

Commit

Permalink
ModelBuilder: add prototype.defineValueType
Browse files Browse the repository at this point in the history
Add a shortcut for registering a new value type.

The current implementation registers the type in the singleton registry
`ModelBuilder.schemaTypes`.

The API should allow us to to change the implementation to register
the type in the scope of ModelBuilder instance only.
  • Loading branch information
Miroslav Bajtoš committed May 23, 2014
1 parent fc758ab commit 487f7c8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/model-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,15 @@ ModelBuilder.prototype.defineProperty = function (model, propertyName, propertyD
this.models[model].registerProperty(propertyName);
};

/**
* Define a new value type that can be used in model schemas as a property type.
* @param {function()} type Type constructor.
* @param {string[]=} aliases Optional list of alternative names for this type.
*/

This comment has been minimized.

Copy link
@raymondfeng

raymondfeng May 23, 2014

Contributor

Maybe just call it defineType or registerType

This comment has been minimized.

Copy link
@bajtos

bajtos May 23, 2014

Member
  • We already have defineClass.
  • Every class is a type too.
  • defineType does not make the distinction clear - can you use defineType to define a class? I would expect that.
ModelBuilder.prototype.defineValueType = function(type, aliases) {
ModelBuilder.registerType(type, aliases);
};

/**
* Extend existing model with bunch of properties
*
Expand Down

0 comments on commit 487f7c8

Please sign in to comment.