Skip to content

Commit

Permalink
v2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainpolletvillard committed Sep 2, 2016
1 parent e31ea6a commit 9e0d2d2
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 16 deletions.
26 changes: 20 additions & 6 deletions dist/object-model.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ObjectModel v2.1.2 - http://objectmodel.js.org
// ObjectModel v2.2.0 - http://objectmodel.js.org
;(function(global){
// string constants
var
Expand Down Expand Up @@ -379,11 +379,25 @@ define(ObjectModelProto, VALIDATOR, function(obj, path, callStack, errorStack){
function getProxy(model, obj, defNode, path) {
if(defNode instanceof Model && obj && !(obj instanceof defNode)) {
return defNode(obj);
} else if(isArray(defNode)){
var suitableModels = defNode.filter(function(part){
return part instanceof Model && obj && !(obj instanceof part) && part.test(obj)
})
return suitableModels.length === 1 ? suitableModels[0](obj) : obj;
} else if(isArray(defNode)){ // union type
var suitableModels = [];
for(var i=0, l=defNode.length; i<l; i++){
var part = defNode[i];
if(part instanceof Model){
if(obj instanceof part){
return obj;
}
if(part.test(obj)){
suitableModels.push(part);
}
}
}
if(suitableModels.length === 1){
return suitableModels[0](obj); // automatically cast to the suitable model when explicit
} else if(suitableModels.length > 1){
console.warn("Ambiguous model for value "+toString(obj)+", could be "+suitableModels.join(" or "));
}
return obj;
} else if(isLeaf(defNode)){
return obj;
} else {
Expand Down
4 changes: 2 additions & 2 deletions dist/object-model.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion dist/object-model.umd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ObjectModel v2.1.2 - http://objectmodel.js.org
// ObjectModel v2.2.0 - http://objectmodel.js.org
;(function (globals, factory) {
if (typeof define === 'function' && define.amd) define(factory); // AMD
else if (typeof exports === 'object') module.exports = factory(); // Node
Expand Down Expand Up @@ -383,6 +383,25 @@ define(ObjectModelProto, VALIDATOR, function(obj, path, callStack, errorStack){
function getProxy(model, obj, defNode, path) {
if(defNode instanceof Model && obj && !(obj instanceof defNode)) {
return defNode(obj);
} else if(isArray(defNode)){ // union type
var suitableModels = [];
for(var i=0, l=defNode.length; i<l; i++){
var part = defNode[i];
if(part instanceof Model){
if(obj instanceof part){
return obj;
}
if(part.test(obj)){
suitableModels.push(part);
}
}
}
if(suitableModels.length === 1){
return suitableModels[0](obj); // automatically cast to the suitable model when explicit
} else if(suitableModels.length > 1){
console.warn("Ambiguous model for value "+toString(obj)+", could be "+suitableModels.join(" or "));
}
return obj;
} else if(isLeaf(defNode)){
return obj;
} else {
Expand Down
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ <h2 id="features">What's inside the box ?</h2>
<li>Constants and private properties based on name conventions</li>
<li>Explicit error messages</li>
<li>Custom error collectors</li>
<li>all in <strong>7 kB minified, 2.9 kB gzipped</strong></li>
<li>all in <strong>7.2 kB minified, 3 kB gzipped</strong></li>
</ul>

<h2 id="browser-support">Which browsers are supported ?</h2>
Expand All @@ -145,11 +145,11 @@ <h2 id="browser-support">Which browsers are supported ?</h2>

<section id="download">
<h2>Download</h2>
<h3>Current version: v2.1.2</h3>
<h3>Current version: v2.2.0</h3>
<ul>
<li>From <a href="https://www.npmjs.com/package/objectmodel">NPM</a> : <code>npm install objectmodel</code></li>
<li>Minified file (7 kB, 2.9 kB gzipped) : <a href="dist/object-model.min.js">object-model.min.js</a></li>
<li>Source files : <a href="https://github.com/sylvainpolletvillard/ObjectModel/archive/v2.1.2.zip">object-model-2.1.2.zip</a> </li>
<li>Minified file (7.2 kB, 3 kB gzipped) : <a href="dist/object-model.min.js">object-model.min.js</a></li>
<li>Source files : <a href="https://github.com/sylvainpolletvillard/ObjectModel/archive/v2.2.0.zip">object-model-2.2.0.zip</a> </li>
</ul>
<h3>Changelog and previous releases</h3>
<p>Checkout the <a target="_blank" href="https://github.com/sylvainpolletvillard/ObjectModel/releases">Github Releases</a></p>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "objectmodel",
"version": "2.1.2",
"version": "2.2.0",
"description": "Runtime Type Checking and Data Model Definition for JavaScript",
"author": "Sylvain Pollet-Villard",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/object-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ define(ObjectModelProto, VALIDATOR, function(obj, path, callStack, errorStack){
function getProxy(model, obj, defNode, path) {
if(defNode instanceof Model && obj && !(obj instanceof defNode)) {
return defNode(obj);
} else if(isArray(defNode)){
} else if(isArray(defNode)){ // union type
var suitableModels = [];
for(var i=0, l=defNode.length; i<l; i++){
var part = defNode[i];
Expand Down
Loading

0 comments on commit 9e0d2d2

Please # to comment.