Permalink
Browse files

Compiled JS with CS 1.3.1

  • Loading branch information...
1 parent d1bd46c commit 11eb8e111cb9a9225eeb30f46be4a7d0f030eb60 @tpett tpett committed Apr 27, 2012
Showing with 269 additions and 96 deletions.
  1. +91 −64 build/knockback.js
  2. +178 −32 build/knockback_test.js
View
@@ -1,6 +1,9 @@
+// Generated by CoffeeScript 1.3.1
(function() {
- var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __slice = Array.prototype.slice;
+ var __slice = [].slice;
+
window.Knockback = {};
+
Knockback.objectReferenceFor = function(className) {
var components, identifier, namespace;
namespace = window;
@@ -10,7 +13,11 @@
}
return namespace;
};
+
Knockback.Relation = (function() {
+
+ Relation.name = 'Relation';
+
function Relation(config) {
if (config == null) {
config = {};
@@ -30,6 +37,7 @@
this.displayName = config.displayName;
this.inverse = config.inverse;
}
+
Relation.prototype.sourceConstructor = function() {
var constructor;
constructor = Knockback.objectReferenceFor(this.sourceClass);
@@ -38,6 +46,7 @@
}
return constructor;
};
+
Relation.prototype.ref = function() {
var nestedAttrs, source;
if (this._cached) {
@@ -52,10 +61,12 @@
}
return this._cached = source;
};
+
Relation.prototype._sourceModel = function(source, attrs) {
source.set(attrs);
return this.target["" + this.name + "_display"](source);
};
+
Relation.prototype._sourceCollection = function(source, models) {
var display;
display = this.target["" + this.name + "_display"];
@@ -77,114 +88,123 @@
return source.reset(models);
}
};
+
return Relation;
+
})();
+
Knockback.Model = Backbone.Model.extend({
initialize: function(attrs, options) {
this._bindProxiedMethods();
this._initRelations(attrs, options);
return this._initAttributes(attrs, options);
},
set: function(attrs, options) {
+ var _this = this;
if (!Backbone.Model.prototype.set.apply(this, [attrs, options])) {
return false;
}
if (this._relationsInitialized) {
- _.each(attrs, __bind(function(value, key) {
+ _.each(attrs, function(value, key) {
var relation;
- if (this.relations[key] && this[key]) {
- relation = this[key].ref(true);
+ if (_this.relations[key] && _this[key]) {
+ relation = _this[key].ref(true);
if (relation.set) {
return relation.set(value, options);
} else if (relation.reset) {
return relation.reset(value, options);
}
}
- }, this));
+ });
}
return this;
},
includeObservables: function() {
- var obj, objs;
+ var obj, objs,
+ _this = this;
objs = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
obj = _.extend.apply(_, [{}].concat(__slice.call(objs)));
- return _.each(_.functions(obj), __bind(function(method) {
- if (this[method]) {
+ return _.each(_.functions(obj), function(method) {
+ if (_this[method]) {
throw "dependentObservable would overwrite existing property or method: '" + method + "'";
}
- return this[method] = ko.dependentObservable(obj[method], this, {
+ return _this[method] = ko.dependentObservable(obj[method], _this, {
deferEvaluation: true
});
- }, this));
+ });
},
parse: function(response, xhr) {
- var responseAttrs;
+ var responseAttrs,
+ _this = this;
if (this.ajaxPrefix) {
responseAttrs = response[this.ajaxPrefix];
- _.each(this.relations, __bind(function(className, relationName) {
+ _.each(this.relations, function(className, relationName) {
if (response[relationName] && !responseAttrs[relationName]) {
return responseAttrs[relationName] = response[relationName];
}
- }, this));
+ });
return responseAttrs;
} else {
return response;
}
},
_bindProxiedMethods: function() {
- var proxiedFunctions;
- proxiedFunctions = _.select(this.proxied || [], __bind(function(methodName) {
- return _.isFunction(this[methodName]);
- }, this));
+ var proxiedFunctions,
+ _this = this;
+ proxiedFunctions = _.select(this.proxied || [], function(methodName) {
+ return _.isFunction(_this[methodName]);
+ });
if (proxiedFunctions.length > 0) {
return _.bindAll.apply(_, [this].concat(__slice.call(proxiedFunctions)));
}
},
_initAttributes: function(attrs, options) {
- var allAttrs, newAttrs;
+ var allAttrs, newAttrs,
+ _this = this;
this.observables = this.observables || {};
newAttrs = {};
this.ID = ko.observable(attrs[this.idAttribute] || null);
- this.bind("change:" + this.idAttribute, __bind(function(model, newId) {
- return this.ID(newId);
- }, this));
- _.each(this.observables, __bind(function(value, key) {
+ this.bind("change:" + this.idAttribute, function(model, newId) {
+ return _this.ID(newId);
+ });
+ _.each(this.observables, function(value, key) {
var safeValue;
safeValue = attrs[key] ? attrs[key] : value && typeof value === 'object' ? _.clone(value) : value;
if (!_.isFunction(value)) {
return newAttrs[key] = safeValue;
}
- }, this));
+ });
allAttrs = _.extend(newAttrs, attrs);
- _.each(allAttrs, __bind(function(value, key) {
- if (!this._wouldOverwriteExistingProperty(key, !!this.observables[key])) {
- return this._initObservable(key, value);
+ _.each(allAttrs, function(value, key) {
+ if (!_this._wouldOverwriteExistingProperty(key, !!_this.observables[key])) {
+ return _this._initObservable(key, value);
}
- }, this));
- _.each(_.functions(this.observables), __bind(function(methodName) {
- if (!this[methodName]) {
+ });
+ _.each(_.functions(this.observables), function(methodName) {
+ if (!_this[methodName]) {
throw "cannot create dependentObservable because model has no method '" + methodName + "'";
}
if (Knockback.Model.prototype[methodName]) {
throw "dependentObservable would override base class method '" + methodName + "'";
}
- return this[methodName] = ko.dependentObservable(this[methodName], this, {
+ return _this[methodName] = ko.dependentObservable(_this[methodName], _this, {
deferEvaluation: true
});
- }, this));
+ });
return this.set(allAttrs, options);
},
_initObservable: function(key, value) {
+ var _this = this;
this[key] = _.isArray(value) ? ko.observableArray(value) : ko.observable(value);
- this.bind("change:" + key, __bind(function(model, newValue) {
- return this[key](newValue);
- }, this));
- return this[key].subscribe(__bind(function(newValue) {
+ this.bind("change:" + key, function(model, newValue) {
+ return _this[key](newValue);
+ });
+ return this[key].subscribe(function(newValue) {
var h;
h = {};
h[key] = newValue;
- return this.set(h);
- }, this));
+ return _this.set(h);
+ });
},
_wouldOverwriteExistingProperty: function(key, raiseOnError) {
if (raiseOnError == null) {
@@ -205,45 +225,49 @@
}
},
_initRelations: function(attrs, options) {
+ var _this = this;
this.relations = this.relations || {};
- _.each(this.relations, __bind(function(className, relationName) {
+ _.each(this.relations, function(className, relationName) {
var klass, relation;
- if (this[relationName]) {
+ if (_this[relationName]) {
throw "relation '" + relationName + "' would overwrite an existing property or method";
}
- relation = this[relationName] = new Knockback.Relation({
+ relation = _this[relationName] = new Knockback.Relation({
name: relationName,
sourceClass: className,
- target: this
+ target: _this
});
klass = relation.sourceConstructor();
if (klass.prototype.set) {
- return this["" + relationName + "_display"] = ko.observable({});
+ return _this["" + relationName + "_display"] = ko.observable({});
} else if (klass.prototype.reset) {
- return this["" + relationName + "_display"] = ko.observableArray();
+ return _this["" + relationName + "_display"] = ko.observableArray();
}
- }, this));
+ });
return this._relationsInitialized = true;
}
});
+
Knockback.Controller = Backbone.Router.extend({
initialize: function(options) {
+ var _this = this;
this._wrapped = {};
- return _.each(this.routes, __bind(function(name, pattern) {
+ return _.each(this.routes, function(name, pattern) {
var handler;
- handler = this.handlerForRoute(name);
- if (handler) {
- return handler.callback = this._wrapped[name] = _.wrap(handler.callback, __bind(function(callback, urlFragment) {
- return this.actionWithFilters(name, callback, urlFragment);
- }, this));
+ handler = _this.handlerForRoute(name);
+ if (handler && !_this._wrapped[name]) {
+ return handler.callback = _this._wrapped[name] = _.wrap(handler.callback, function(callback, urlFragment) {
+ return _this.actionWithFilters(name, callback, urlFragment);
+ });
}
- }, this));
+ });
},
inverseRoutes: function() {
- return this._inverseRoutes || (this._inverseRoutes = _.reduce(this.routes, (__bind(function(memo, name, pattern) {
- memo[name] = this._routeToRegExp(pattern).toString();
+ var _this = this;
+ return this._inverseRoutes || (this._inverseRoutes = _.reduce(this.routes, (function(memo, name, pattern) {
+ memo[name] = _this._routeToRegExp(pattern).toString();
return memo;
- }, this)), {}));
+ }), {}));
},
handlerForRoute: function(routeName) {
var handlers, routeExp;
@@ -254,26 +278,29 @@
});
},
actionWithFilters: function(name, action, urlFragment) {
- _.each(this.filtersForAction(name, 'before'), __bind(function(filter) {
- return filter.apply(this, [urlFragment]);
- }, this));
+ var _this = this;
+ _.each(this.filtersForAction(name, 'before'), function(filter) {
+ return filter.apply(_this, [urlFragment]);
+ });
action(urlFragment);
- return _.each(this.filtersForAction(name, 'after'), __bind(function(filter) {
- return filter.apply(this, [urlFragment]);
- }, this));
+ return _.each(this.filtersForAction(name, 'after'), function(filter) {
+ return filter.apply(_this, [urlFragment]);
+ });
},
filtersForAction: function(actionName, filterType) {
- var action_filters, global_filters, methodNames;
+ var action_filters, global_filters, methodNames,
+ _this = this;
if (!this.inverseRoutes()[actionName]) {
throw "cannot run filters for non-existent action, '" + actionName + "'";
}
this.filters || (this.filters = {});
global_filters = this.filters[filterType] || [];
action_filters = this.filters["" + filterType + "_" + actionName] || [];
methodNames = [].concat(global_filters, action_filters);
- return _.map(methodNames, __bind(function(methodName) {
- return this[methodName];
- }, this));
+ return _.map(methodNames, function(methodName) {
+ return _this[methodName];
+ });
}
});
+
}).call(this);
Oops, something went wrong.

0 comments on commit 11eb8e1

Please sign in to comment.