Comparing version 0.5.0 to 0.6.1
103
build/bam.js
@@ -93,3 +93,3 @@ (function(e){if("function"==typeof bootstrap)bootstrap("bam",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeBam=e}else"undefined"!=typeof window?window.Bam=e():global.Bam=e()})(function(){var define,ses,bootstrap,module,exports; | ||
},{"./decoratable.js":2,"backbone":"/GJ2HT"}],2:[function(require,module,exports){ | ||
},{"./decoratable.js":2,"backbone":"qnWQXd"}],2:[function(require,module,exports){ | ||
// Generated by CoffeeScript 1.6.3 | ||
@@ -166,3 +166,3 @@ (function() { | ||
},{"underscore":"Ik6GN6"}],3:[function(require,module,exports){ | ||
},{"underscore":"hZlnRu"}],3:[function(require,module,exports){ | ||
// Generated by CoffeeScript 1.6.3 | ||
@@ -187,3 +187,3 @@ /* | ||
(function() { | ||
var $, Backbone, Decoratable, Model, _, _ref, | ||
var Backbone, Decoratable, Model, _, _ref, | ||
__hasProp = {}.hasOwnProperty, | ||
@@ -196,4 +196,2 @@ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | ||
$ = require('jquery-browserify'); | ||
Decoratable = require('./decoratable.js'); | ||
@@ -251,2 +249,93 @@ | ||
/* | ||
Override the set method to allow for casting as data comes in. | ||
*/ | ||
Model.prototype.set = function(key, val, options) { | ||
var attrs; | ||
if (typeof key === 'object') { | ||
attrs = key; | ||
options = val; | ||
} else { | ||
attrs = {}; | ||
attrs[key] = val; | ||
} | ||
if (this.types) { | ||
for (key in attrs) { | ||
val = attrs[key]; | ||
if (!_.isUndefined(this.types[key])) { | ||
attrs[key] = this.cast(val, this.types[key]); | ||
} | ||
} | ||
} | ||
return Model.__super__.set.call(this, attrs, options); | ||
}; | ||
/* | ||
Take a value, and a casting definition and perform the cast | ||
*/ | ||
Model.prototype.cast = function(value, cast) { | ||
var error; | ||
try { | ||
return value = this.getCastFunc(cast)(value); | ||
} catch (_error) { | ||
error = _error; | ||
return value = null; | ||
} finally { | ||
return value; | ||
} | ||
}; | ||
/* | ||
Given a casting definition, return a function that should perform the cast | ||
*/ | ||
Model.prototype.getCastFunc = function(cast) { | ||
if (_.isFunction(cast)) { | ||
return cast; | ||
} | ||
switch (cast) { | ||
case 'string': | ||
return function(v) { | ||
if (v === null) { | ||
return null; | ||
} else { | ||
return v + ''; | ||
} | ||
}; | ||
case 'int': | ||
return function(v) { | ||
if (v === null) { | ||
return null; | ||
} else { | ||
return Math.floor(+v); | ||
} | ||
}; | ||
case 'float': | ||
return function(v) { | ||
if (v === null) { | ||
return null; | ||
} else { | ||
return +v; | ||
} | ||
}; | ||
case 'boolean': | ||
return function(v) { | ||
if (v === null) { | ||
return null; | ||
} else { | ||
return !!v; | ||
} | ||
}; | ||
default: | ||
return function(v) { | ||
return v; | ||
}; | ||
} | ||
}; | ||
return Model; | ||
@@ -260,3 +349,3 @@ | ||
},{"./decoratable.js":2,"backbone":"/GJ2HT","jquery-browserify":"xsaEYa","underscore":"Ik6GN6"}],5:[function(require,module,exports){ | ||
},{"./decoratable.js":2,"backbone":"qnWQXd","underscore":"hZlnRu"}],5:[function(require,module,exports){ | ||
// Generated by CoffeeScript 1.6.3 | ||
@@ -751,4 +840,4 @@ (function() { | ||
},{"./decoratable.js":2,"backbone":"/GJ2HT","jquery-browserify":"xsaEYa","underscore":"Ik6GN6"}]},{},[3])(3) | ||
},{"./decoratable.js":2,"backbone":"qnWQXd","jquery-browserify":"xPEZ/r","underscore":"hZlnRu"}]},{},[3])(3) | ||
}); | ||
; |
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
var $, Backbone, Decoratable, Model, _, _ref, | ||
var Backbone, Decoratable, Model, _, _ref, | ||
__hasProp = {}.hasOwnProperty, | ||
@@ -11,4 +11,2 @@ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | ||
$ = require('jquery-browserify'); | ||
Decoratable = require('./decoratable.js'); | ||
@@ -66,2 +64,93 @@ | ||
/* | ||
Override the set method to allow for casting as data comes in. | ||
*/ | ||
Model.prototype.set = function(key, val, options) { | ||
var attrs; | ||
if (typeof key === 'object') { | ||
attrs = key; | ||
options = val; | ||
} else { | ||
attrs = {}; | ||
attrs[key] = val; | ||
} | ||
if (this.types) { | ||
for (key in attrs) { | ||
val = attrs[key]; | ||
if (!_.isUndefined(this.types[key])) { | ||
attrs[key] = this.cast(val, this.types[key]); | ||
} | ||
} | ||
} | ||
return Model.__super__.set.call(this, attrs, options); | ||
}; | ||
/* | ||
Take a value, and a casting definition and perform the cast | ||
*/ | ||
Model.prototype.cast = function(value, cast) { | ||
var error; | ||
try { | ||
return value = this.getCastFunc(cast)(value); | ||
} catch (_error) { | ||
error = _error; | ||
return value = null; | ||
} finally { | ||
return value; | ||
} | ||
}; | ||
/* | ||
Given a casting definition, return a function that should perform the cast | ||
*/ | ||
Model.prototype.getCastFunc = function(cast) { | ||
if (_.isFunction(cast)) { | ||
return cast; | ||
} | ||
switch (cast) { | ||
case 'string': | ||
return function(v) { | ||
if (v === null) { | ||
return null; | ||
} else { | ||
return v + ''; | ||
} | ||
}; | ||
case 'int': | ||
return function(v) { | ||
if (v === null) { | ||
return null; | ||
} else { | ||
return Math.floor(+v); | ||
} | ||
}; | ||
case 'float': | ||
return function(v) { | ||
if (v === null) { | ||
return null; | ||
} else { | ||
return +v; | ||
} | ||
}; | ||
case 'boolean': | ||
return function(v) { | ||
if (v === null) { | ||
return null; | ||
} else { | ||
return !!v; | ||
} | ||
}; | ||
default: | ||
return function(v) { | ||
return v; | ||
}; | ||
} | ||
}; | ||
return Model; | ||
@@ -68,0 +157,0 @@ |
{ | ||
"name": "bamjs", | ||
"version": "0.5.0", | ||
"version": "0.6.1", | ||
"description": "Backbone with modifications. Adds heirarchy to Views, turns Views into Finite State Machines, adds a mixin for decorating methods and adds utility functions to Models and Collections.", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"prepublish": "./bin/prepublish.sh" | ||
}, | ||
@@ -38,6 +38,3 @@ "repository": { | ||
"browserify": "~2.27.1" | ||
}, | ||
"scripts": { | ||
"prepublish": "./bin/prepublish.sh" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47856
1322