Permalink
Browse files

Removing leafs() mechanism, because it cannot handle recursive struct…

…ures.
  • Loading branch information...
1 parent 600b9a3 commit 564d84b60b7734e2cdb6c08661c59b9a8452d740 @molnarg committed Aug 18, 2012
Showing with 2 additions and 59 deletions.
  1. +2 −16 lib/Schema.js
  2. +0 −10 lib/extensions/Array.js
  3. +0 −20 lib/patterns/object.js
  4. +0 −13 lib/patterns/or.js
View
18 lib/Schema.js
@@ -4,24 +4,10 @@ var def = require('def.js')
var Schema = module.exports = function() {}
Schema.prototype = {
- leafs : function() {
- return { certain : [ this ], uncertain : [] }
- },
-
seal : function() {
if (this.sealed) return this.validate
this.sealed = true
-
- if (this.leafs) {
- var leafs = this.leafs()
- if (leafs.certain.indexOf(Schema.self) !== -1) {
- throw new Error('There\'s no object that satisfies this schema.')
- }
- if (leafs.uncertain.indexOf(Schema.self) !== -1) {
- // schema.self needs to be pointed to this schema, and then it must be reset
- Schema.self.resolve(this)
- }
- }
+ Schema.self.resolve(this)
return this.validate
},
@@ -30,7 +16,7 @@ Schema.prototype = {
if (this.wrapped) return this.validate
this.wrapped = true
- var publicFunctions = [ 'seal', 'toJSON', 'generate', 'leafs', 'unwrap' ]
+ var publicFunctions = [ 'seal', 'toJSON', 'generate', 'unwrap' ]
publicFunctions = publicFunctions.concat(this.publicFunctions || [])
for (var i = 0; i < publicFunctions.length; i++) {
View
10 lib/extensions/Array.js
@@ -41,16 +41,6 @@ var ArraySchema = module.exports = Schema.extend({
return array
},
- leafs : function() {
- var item_leafs = this.itemSchema.leafs()
-
- if (this.min > 0) return item_leafs
-
- return { certain : []
- , uncertain : _.union(item_leafs.certain, item_leafs.uncertain)
- }
- },
-
toJSON : Schema.session(function() {
var json = Schema.prototype.toJSON.call(this, true)
View
20 lib/patterns/object.js
@@ -94,26 +94,6 @@ var ObjectSchema = module.exports = Schema.extend({
return object
},
- leafs : function() {
- var certain = [], uncertain = []
-
- this.properties.forEach(function(property) {
- var property_leafs = property.value.leafs()
-
- if (property.min > 0) {
- certain.push(property_leafs.certain)
- uncertain.push(property_leafs.uncertain)
- } else {
- uncertain.push(property_leafs.uncertain)
- uncertain.push(property_leafs.certain)
- }
- })
-
- return { certain : _.union.apply(null, certain)
- , uncertain : _.union.apply(null, uncertain.concat([this.other]))
- }
- },
-
toJSON : Schema.session(function() {
var i, property, regexp, json = Schema.prototype.toJSON.call(this, true)
View
13 lib/patterns/or.js
@@ -17,19 +17,6 @@ var OrSchema = module.exports = Schema.extend({
return this.schemas[Math.floor(Math.random()*this.schemas.length)].generate()
},
- leafs : function() {
- // Certain and uncertain leafs of subschemas
- var subschema_certain = this.schemas.map(function(sub) { return sub.leafs().certain })
- , subschema_uncertain = this.schemas.map(function(sub) { return sub.leafs().uncertain })
- , subschema_all = _.union.apply(null, subschema_certain.concat(subschema_uncertain))
-
- // If some leaf appears in all subschemas as certain then it is certain. Otherwise uncertain.
- var certain = _.intersection.apply(null, subschema_certain)
- , uncertain = _.difference(subschema_all, certain)
-
- return { certain : certain, uncertain : uncertain }
- },
-
toJSON : Schema.session(function() {
var json = Schema.prototype.toJSON.call(this, true)
, subjsons = this.schemas.map(function(sch) { return sch.toJSON() })

0 comments on commit 564d84b

Please sign in to comment.