2013-06-22 06:24:24 +00:00
|
|
|
'use strict';
|
2013-06-24 23:41:59 +00:00
|
|
|
define(
|
|
|
|
[
|
|
|
|
'signalR'
|
|
|
|
], function () {
|
|
|
|
|
2013-08-21 19:07:28 +00:00
|
|
|
_.extend(Backbone.Collection.prototype, {
|
2013-09-11 06:33:47 +00:00
|
|
|
bindSignalR: function () {
|
2013-06-24 23:41:59 +00:00
|
|
|
|
2013-09-11 06:33:47 +00:00
|
|
|
var collection = this;
|
2013-05-06 00:33:43 +00:00
|
|
|
|
2013-09-11 06:33:47 +00:00
|
|
|
var processMessage = function (options) {
|
2013-05-05 21:24:33 +00:00
|
|
|
|
2013-09-11 06:33:47 +00:00
|
|
|
var model = new collection.model(options.resource, {parse: true});
|
|
|
|
collection.add(model, {merge: true});
|
|
|
|
console.log(options.action + ": %O", options.resource);
|
2013-08-21 19:07:28 +00:00
|
|
|
};
|
|
|
|
|
2013-09-11 06:33:47 +00:00
|
|
|
require(
|
2013-08-21 19:07:28 +00:00
|
|
|
[
|
2013-09-11 06:33:47 +00:00
|
|
|
'app'
|
|
|
|
], function (app) {
|
|
|
|
collection.listenTo(app.vent, 'server:' + collection.url.replace('/api/', ''), processMessage)
|
|
|
|
});
|
2013-08-10 18:38:01 +00:00
|
|
|
|
2013-08-21 19:07:28 +00:00
|
|
|
return this;
|
|
|
|
},
|
2013-08-10 18:38:01 +00:00
|
|
|
|
2013-08-21 19:07:28 +00:00
|
|
|
unbindSignalR: function () {
|
2013-08-10 18:38:01 +00:00
|
|
|
|
2013-05-06 00:33:43 +00:00
|
|
|
|
2013-08-21 19:07:28 +00:00
|
|
|
}});
|
2013-06-24 23:41:59 +00:00
|
|
|
});
|
2013-05-06 00:33:43 +00:00
|
|
|
|
|
|
|
|