From ebadd6b1d585ddaeddbdf54210a17dad905bf749 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Wed, 23 Jan 2013 16:09:02 -0800 Subject: [PATCH] added backbone.debug --- NzbDrone.Web/NzbDrone.Web.csproj | 8 +- .../JsLibraries/backbone.debug.js | 131 ++++++++++++++++++ NzbDrone.Web/_backboneApp/app.js | 1 + 3 files changed, 135 insertions(+), 5 deletions(-) create mode 100644 NzbDrone.Web/_backboneApp/JsLibraries/backbone.debug.js diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index 711d3d804..ea166991c 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -74,9 +74,6 @@ ..\packages\Cassette.Less.2.0.0\lib\net40-client\Cassette.Less.dll - - ..\packages\Cassette.MSBuild.2.0.0\lib\net40\Cassette.MSBuild.dll - ..\packages\Cassette.Views.2.0.0\lib\net40\Cassette.Views.dll @@ -185,6 +182,7 @@ + @@ -380,8 +378,9 @@ - + + @@ -785,5 +784,4 @@ xcopy /s /y "$(SolutionDir)packages\Microsoft.SqlServer.Compact.4.0.8876.1\NativeBinaries\x86\*.*" "$(TargetDir)x86" - \ No newline at end of file diff --git a/NzbDrone.Web/_backboneApp/JsLibraries/backbone.debug.js b/NzbDrone.Web/_backboneApp/JsLibraries/backbone.debug.js new file mode 100644 index 000000000..59d200245 --- /dev/null +++ b/NzbDrone.Web/_backboneApp/JsLibraries/backbone.debug.js @@ -0,0 +1,131 @@ +(function () { + var __bind = function (fn, me) { return function () { return fn.apply(me, arguments); }; }; + + window.Backbone.Debug = (function () { + + function Debug() { + this._hookPrototype = __bind(this._hookPrototype, this); + this._hookMethod = __bind(this._hookMethod, this); + this._logSync = __bind(this._logSync, this); + this._logEvent = __bind(this._logEvent, this); + this._saveObjects = __bind(this._saveObjects, this); + this._hookSync = __bind(this._hookSync, this); + this._hookEvents = __bind(this._hookEvents, this); + this._trackObjects = __bind(this._trackObjects, this); + this.off = __bind(this.off, this); + this.on = __bind(this.on, this); + this.routers = __bind(this.routers, this); + this.views = __bind(this.views, this); + this.models = __bind(this.models, this); + this.collections = __bind(this.collections, this); this._options = { + 'log:events': true, + 'log:sync': true + }; + this._objects = { + Collection: {}, + Model: {}, + View: {}, + Router: {} + }; + this._trackObjects(); + this._hookEvents(); + this._hookSync(); + } + + Debug.prototype.collections = function () { + return this._objects.Collection; + }; + + Debug.prototype.models = function () { + return this._objects.Model; + }; + + Debug.prototype.views = function () { + return this._objects.View; + }; + + Debug.prototype.routers = function () { + return this._objects.Router; + }; + + Debug.prototype.on = function (option) { + if (option != null) { + return this._options[option] = true; + } else { + this._options['log:events'] = true; + return this._options['log:sync'] = true; + } + }; + + Debug.prototype.off = function (option) { + if (option != null) { + return this._options[option] = false; + } else { + this._options['log:events'] = false; + return this._options['log:sync'] = false; + } + }; + + Debug.prototype._trackObjects = function () { + this._hookPrototype('Collection', 'constructor', this._saveObjects); + this._hookPrototype('Model', 'constructor', this._saveObjects); + this._hookPrototype('View', 'constructor', this._saveObjects); + return this._hookPrototype('Router', 'constructor', this._saveObjects); + }; + + Debug.prototype._hookEvents = function () { + this._hookPrototype('Collection', 'trigger', this._logEvent); + this._hookPrototype('Model', 'trigger', this._logEvent); + this._hookPrototype('View', 'trigger', this._logEvent); + return this._hookPrototype('Router', 'trigger', this._logEvent); + }; + + Debug.prototype._hookSync = function () { + return this._hookMethod('sync', this._logSync); + }; + + Debug.prototype._saveObjects = function (type, method, object) { + return this._objects[type][object.constructor.name + ':' + object.cid] = object; + }; + + Debug.prototype._logEvent = function (parent_object, method, object, args) { + if (this._options['log:events']) { + return console.log("" + args[0] + " - ", object); + } + }; + + Debug.prototype._logSync = function (method, object, args) { + if (this._options['log:sync'] === true) { + return console.log("sync - " + args[0], args[1]); + } + }; + + Debug.prototype._hookMethod = function (method, action) { + var original; + original = window.Backbone[method]; + return window.Backbone[method] = function () { + var ret; + ret = original.apply(this, arguments); + action(method, this, arguments); + return ret; + }; + }; + + Debug.prototype._hookPrototype = function (object, method, action) { + var original; + original = window.Backbone[object].prototype[method]; + return window.Backbone[object].prototype[method] = function () { + var ret; + ret = original.apply(this, arguments); + action(object, method, this, arguments); + return ret; + }; + }; + + return Debug; + + })(); + + window.Backbone.debug = new Backbone.Debug(); + +}).call(this); \ No newline at end of file diff --git a/NzbDrone.Web/_backboneApp/app.js b/NzbDrone.Web/_backboneApp/app.js index 24de3d2c4..489185678 100644 --- a/NzbDrone.Web/_backboneApp/app.js +++ b/NzbDrone.Web/_backboneApp/app.js @@ -1,6 +1,7 @@ /// /// /// +/// /// /// ///