kendo.data.signalr.js
7.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* Kendo UI v2016.1.112 (http://www.telerik.com/kendo-ui)
* Copyright 2016 Telerik AD. All rights reserved.
*
* Kendo UI commercial licenses may be obtained at
* http://www.telerik.com/purchase/license-agreement/kendo-ui-complete
* If you do not own a commercial license, this file shall be governed by the trial license terms.
*/
(function (f, define) {
define('kendo.data.signalr', ['kendo.data'], f);
}(function () {
var __meta__ = {
id: 'data.signalr',
name: 'SignalR',
category: 'framework',
depends: ['data'],
hidden: true
};
(function ($) {
var transport = kendo.data.RemoteTransport.extend({
init: function (options) {
var signalr = options && options.signalr ? options.signalr : {};
var promise = signalr.promise;
if (!promise) {
throw new Error('The "promise" option must be set.');
}
if (typeof promise.done != 'function' || typeof promise.fail != 'function') {
throw new Error('The "promise" option must be a Promise.');
}
this.promise = promise;
var hub = signalr.hub;
if (!hub) {
throw new Error('The "hub" option must be set.');
}
if (typeof hub.on != 'function' || typeof hub.invoke != 'function') {
throw new Error('The "hub" option is not a valid SignalR hub proxy.');
}
this.hub = hub;
kendo.data.RemoteTransport.fn.init.call(this, options);
},
push: function (callbacks) {
var client = this.options.signalr.client || {};
if (client.create) {
this.hub.on(client.create, callbacks.pushCreate);
}
if (client.update) {
this.hub.on(client.update, callbacks.pushUpdate);
}
if (client.destroy) {
this.hub.on(client.destroy, callbacks.pushDestroy);
}
},
_crud: function (options, type) {
var hub = this.hub;
var server = this.options.signalr.server;
if (!server || !server[type]) {
throw new Error(kendo.format('The "server.{0}" option must be set.', type));
}
var args = [server[type]];
var data = this.parameterMap(options.data, type);
if (!$.isEmptyObject(data)) {
args.push(data);
}
this.promise.done(function () {
hub.invoke.apply(hub, args).done(options.success).fail(options.error);
});
},
read: function (options) {
this._crud(options, 'read');
},
create: function (options) {
this._crud(options, 'create');
},
update: function (options) {
this._crud(options, 'update');
},
destroy: function (options) {
this._crud(options, 'destroy');
}
});
$.extend(true, kendo.data, { transports: { signalr: transport } });
}(window.kendo.jQuery));
return window.kendo;
}, typeof define == 'function' && define.amd ? define : function (a1, a2, a3) {
(a3 || a2)();
}));