Permalink
Browse files

Getting rid of def.js dependency.

  • Loading branch information...
molnarg committed Aug 18, 2012
1 parent d2a3b06 commit 61398b448ced975492ce23c541e3d3606b1822ec
Showing with 14 additions and 10 deletions.
  1. +14 −9 lib/Schema.js
  2. +0 −1 package.json
View
@@ -1,5 +1,3 @@
-var def = require('def.js')
-
var Schema = module.exports = function() {}
Schema.prototype = {
@@ -60,7 +58,7 @@ Schema.prototype = {
var active = false
function session(f) {
- var proxy = function() {
+ return function() {
if (active) {
// There's an active session, just forwarding to the original function
return f.apply(this, arguments)
@@ -78,17 +76,24 @@ function session(f) {
return result
}
}
-
- for (var i in f) proxy[i] = f[i].bind(f)
-
- return proxy
}
Schema.session = session
-Schema.fromJS = def()
+function lastDefinedResult(functions, arg) {
+ var i = functions.length, result;
+ while (i--) {
+ result = functions[i](arg)
+ if (result != null) return result
+ }
+}
-Schema.fromJSON = Schema.session(def())
+var fromJSdefs = []
+Schema.fromJS = lastDefinedResult.bind(null, fromJSdefs)
+Schema.fromJS.def = Array.prototype.push.bind(fromJSdefs)
+var fromJSONdefs = []
+Schema.fromJSON = session(lastDefinedResult.bind(null, fromJSONdefs))
+Schema.fromJSON.def = Array.prototype.push.bind(fromJSONdefs)
Schema.extend = function(descriptor) {
if (!descriptor.validate) {
View
@@ -16,7 +16,6 @@
"url": "git@github.com:molnarg/js-schema.git"
},
"dependencies": {
- "def.js" : "*",
"randexp" : "*"
},
"devDependencies": {},

0 comments on commit 61398b4

Please sign in to comment.