removed leak from signalr

pull/4/head
Keivan Beigi 11 years ago
parent 5327068557
commit 66ce8e8b27

@ -11,7 +11,7 @@ define(
model: RootFolderModel model: RootFolderModel
}); });
var collection = new RootFolderCollection().BindSignalR(); var collection = new RootFolderCollection().bindSignalR();
return collection; return collection;
}); });

@ -4,7 +4,8 @@ define(
'signalR' 'signalR'
], function () { ], function () {
_.extend(Backbone.Collection.prototype, {BindSignalR: function (options) { _.extend(Backbone.Collection.prototype, {
bindSignalR: function (options) {
if (!options) { if (!options) {
options = {}; options = {};
@ -12,7 +13,7 @@ define(
if (!options.url) { if (!options.url) {
console.assert(this.url, 'url must be provided or collection must have url'); console.assert(this.url, 'url must be provided or collection must have url');
options['url'] = this.url.replace('api', 'signalr'); options.url = this.url.replace('api', 'signalr');
} }
var self = this; var self = this;
@ -30,35 +31,34 @@ define(
default: default:
throw 'invalid status ' + status; throw 'invalid status ' + status;
} }
}; };
var connection = $.connection(options.url); this.signalRconnection = $.connection(options.url);
connection.stateChanged(function (change) { this.signalRconnection.stateChanged(function (change) {
console.debug('{0} [{1}]'.format(options.url, _getStatus(change.newState))); console.debug('{0} [{1}]'.format(options.url, _getStatus(change.newState)));
}); });
connection.received(function (message) { this.signalRconnection.received(function (message) {
console.debug(message); console.debug(message);
if (options.onReceived) {
var context = options.context || self;
options.onReceived.call(context, message);
}
else {
self.fetch(); self.fetch();
}
}); });
connection.start({ transport: this.signalRconnection.start({ transport:
[ [
'longPolling' 'longPolling'
] }); ] });
return this; return this;
},
unbindSignalR: function () {
if(this.signalRconnection){
this.signalRconnection.stop();
delete this.signalRconnection;
}
}}); }});
}); });

@ -56,7 +56,7 @@ define(
var fanArt = this._getFanArt(); var fanArt = this._getFanArt();
if (fanArt) { if (fanArt) {
$.backstretch(fanArt); this._backstrech = $.backstretch(fanArt);
} }
else { else {
$('body').removeClass('backdrop'); $('body').removeClass('backdrop');
@ -78,7 +78,12 @@ define(
}, },
onClose: function () { onClose: function () {
$('.backstretch').remove();
if (this._backstrech) {
this._backstrech.destroy();
delete this._backstrech;
}
$('body').removeClass('backdrop'); $('body').removeClass('backdrop');
}, },
@ -170,10 +175,10 @@ define(
series : self.model series : self.model
}); });
self.episodeCollection.BindSignalR({ /* self.episodeCollection.bindSignalR({
onReceived: seasonCollectionView.onEpisodeGrabbed, onReceived: seasonCollectionView.onEpisodeGrabbed,
context : seasonCollectionView context : seasonCollectionView
}); });*/
self.seasons.show(seasonCollectionView); self.seasons.show(seasonCollectionView);

Loading…
Cancel
Save