You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Sonarr/UI/Mixins/backbone.signalr.mixin.js

44 lines
1.1 KiB

'use strict';
define(
[
11 years ago
'underscore',
'backbone',
'signalR'
11 years ago
], function (_, Backbone) {
_.extend(Backbone.Collection.prototype, {
11 years ago
bindSignalR: function () {
11 years ago
var collection = this;
11 years ago
var processMessage = function (options) {
if (options.action === 'sync') {
console.log('sync received, refetching collection');
collection.fetch();
return;
}
11 years ago
var model = new collection.model(options.resource, {parse: true});
collection.add(model, {merge: true});
11 years ago
console.log(options.action + ': {0}}'.format(options.resource));
};
11 years ago
require(
[
11 years ago
'app'
], function (app) {
11 years ago
collection.listenTo(app.vent, 'server:' + collection.url.replace('/api/', ''), processMessage);
11 years ago
});
return this;
},
unbindSignalR: function () {
}});
});