forked from Breeze/breeze.js.labs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
breeze.to$q.shim.js
72 lines (63 loc) · 2.38 KB
/
breeze.to$q.shim.js
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
// Legacy. Support apps that followed old recommendation of adding to$q
// to the end of Breeze methods that returned Q.js promises.
// Althought harmless, we don't need or want it with this module.
// But it may take time to remove to$q from an existing app.
// Remove this shim when you have replaced all references to "to$q" with "then" in your app.
(function (definition, window) {
if (window.breeze) {
definition(window.breeze);
} else if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
// CommonJS or Node
var b = require('breeze');
definition(b);
} else if (typeof define === "function" && define["amd"] && !window.breeze) {
// Requirejs / AMD
define(['breeze'], definition);
} else {
throw new Error("Can't find breeze");
}
}(function (breeze) {
// EntityManager
var proto = breeze.EntityManager.prototype;
var executeQuery = proto.executeQuery;
if (-1 < executeQuery.toString().indexOf('extendWith_to$q')) {
return; // already extended Breeze
}
proto.executeQuery =
function () {
var promise = executeQuery.apply(this, arguments);
return extendWith_to$q(promise);
};
var e_fetchMetadata = proto.fetchMetadata;
proto.fetchMetadata =
function () {
var promise = e_fetchMetadata.apply(this, arguments);
return extendWith_to$q(promise);
};
var fetchEntityByKey = proto.fetchEntityByKey;
proto.fetchEntityByKey =
function () {
var promise = fetchEntityByKey.apply(this, arguments);
return extendWith_to$q(promise);
};
var saveChanges = proto.saveChanges;
proto.saveChanges =
function () {
var promise = saveChanges.apply(this, arguments);
return extendWith_to$q(promise);
};
// MetadataStore
proto = breeze.MetadataStore.prototype;
var m_fetchMetadata = proto.fetchMetadata;
proto.fetchMetadata =
function () {
var promise = m_fetchMetadata.apply(this, arguments);
return extendWith_to$q(promise);
};
function extendWith_to$q(promise) {
promise.to$q = function (success, fail) {
return (success || fail) ? promise.then(success, fail) : promise;
};
return promise;
}
}, this));