From 66ce8e8b2737a7be629bee9be208eaaa42764e33 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Wed, 21 Aug 2013 12:07:28 -0700 Subject: [PATCH] removed leak from signalr --- UI/AddSeries/RootFolders/Collection.js | 2 +- UI/Mixins/backbone.signalr.mixin.js | 96 ++++++++++++------------ UI/Series/Details/SeriesDetailsLayout.js | 19 +++-- 3 files changed, 61 insertions(+), 56 deletions(-) diff --git a/UI/AddSeries/RootFolders/Collection.js b/UI/AddSeries/RootFolders/Collection.js index fdac81123..8f20ac92a 100644 --- a/UI/AddSeries/RootFolders/Collection.js +++ b/UI/AddSeries/RootFolders/Collection.js @@ -11,7 +11,7 @@ define( model: RootFolderModel }); - var collection = new RootFolderCollection().BindSignalR(); + var collection = new RootFolderCollection().bindSignalR(); return collection; }); diff --git a/UI/Mixins/backbone.signalr.mixin.js b/UI/Mixins/backbone.signalr.mixin.js index 6b1f9ce9e..39b309f2a 100644 --- a/UI/Mixins/backbone.signalr.mixin.js +++ b/UI/Mixins/backbone.signalr.mixin.js @@ -4,62 +4,62 @@ define( 'signalR' ], function () { - _.extend(Backbone.Collection.prototype, {BindSignalR: function (options) { + _.extend(Backbone.Collection.prototype, { + bindSignalR: function (options) { - if (!options) { - options = {}; - } - - if (!options.url) { - console.assert(this.url, 'url must be provided or collection must have url'); - options['url'] = this.url.replace('api', 'signalr'); - } - - var self = this; - - var _getStatus = function (status) { - switch (status) { - case 0: - return 'connecting'; - case 1: - return 'connected'; - case 2: - return 'reconnecting'; - case 4: - return 'disconnected'; - default: - throw 'invalid status ' + status; + if (!options) { + options = {}; } - }; - - var connection = $.connection(options.url); - - connection.stateChanged(function (change) { - console.debug('{0} [{1}]'.format(options.url, _getStatus(change.newState))); - }); - - connection.received(function (message) { - console.debug(message); - - if (options.onReceived) { - var context = options.context || self; - - options.onReceived.call(context, message); + if (!options.url) { + console.assert(this.url, 'url must be provided or collection must have url'); + options.url = this.url.replace('api', 'signalr'); } - else { + var self = this; + + var _getStatus = function (status) { + switch (status) { + case 0: + return 'connecting'; + case 1: + return 'connected'; + case 2: + return 'reconnecting'; + case 4: + return 'disconnected'; + default: + throw 'invalid status ' + status; + } + }; + + this.signalRconnection = $.connection(options.url); + + this.signalRconnection.stateChanged(function (change) { + console.debug('{0} [{1}]'.format(options.url, _getStatus(change.newState))); + }); + + this.signalRconnection.received(function (message) { + console.debug(message); self.fetch(); + }); + + this.signalRconnection.start({ transport: + [ + 'longPolling' + ] }); + + return this; + }, + + unbindSignalR: function () { + + if(this.signalRconnection){ + this.signalRconnection.stop(); + delete this.signalRconnection; } - }); - connection.start({ transport: - [ - 'longPolling' - ] }); - - return this; - }}); + }}); }); diff --git a/UI/Series/Details/SeriesDetailsLayout.js b/UI/Series/Details/SeriesDetailsLayout.js index 7caf68aee..810d2c502 100644 --- a/UI/Series/Details/SeriesDetailsLayout.js +++ b/UI/Series/Details/SeriesDetailsLayout.js @@ -56,7 +56,7 @@ define( var fanArt = this._getFanArt(); if (fanArt) { - $.backstretch(fanArt); + this._backstrech = $.backstretch(fanArt); } else { $('body').removeClass('backdrop'); @@ -78,7 +78,12 @@ define( }, onClose: function () { - $('.backstretch').remove(); + + if (this._backstrech) { + this._backstrech.destroy(); + delete this._backstrech; + } + $('body').removeClass('backdrop'); }, @@ -120,8 +125,8 @@ define( }, element : this.ui.refresh, leaveIcon : true, - context: this, - onSuccess: this._showSeasons + context : this, + onSuccess : this._showSeasons }); }, @@ -170,15 +175,15 @@ define( series : self.model }); - self.episodeCollection.BindSignalR({ + /* self.episodeCollection.bindSignalR({ onReceived: seasonCollectionView.onEpisodeGrabbed, context : seasonCollectionView - }); + });*/ self.seasons.show(seasonCollectionView); self.seasonMenu.show(new SeasonMenuCollectionView({ - collection: self.seasonCollection, + collection : self.seasonCollection, episodeCollection: self.episodeCollection })); });