-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathpatch_youtube_client.js
46 lines (41 loc) · 1.37 KB
/
patch_youtube_client.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
function googleClientReady() {
// Zone.js no longer exposes those two utils. Copy-pasta.
var patchPrototype = function (obj, fnNames) {
fnNames.forEach(function (name) {
var delegate = obj[name];
if (delegate) {
obj[name] = function () {
return delegate.apply(this, bindArguments(arguments));
};
}
});
};
var bindArguments = function (args) {
for (var i = args.length - 1; i >= 0; i--) {
if (typeof args[i] === 'function') {
args[i] = zone.bind(args[i]);
}
}
return args;
};
/**
* This patches the Promise library of the GoogleClient. If it would be using native promises
* this would not be necessary.
*
* The issue is that the GoogleClientPromise gets triggerd from a callback which was registered before
* angular bootstraped and hence all `then`s execute in the wrong zone. If GoogleClient would use
* native Promise, this would not be a problem, but it does not, hence we patch the GoogleClientPromise
* to behave the same as native Promise.
*/
gapi.client.load = (function(delegate) {
return function(name, ver) {
var promise = delegate.call(this, name, ver);
patchPrototype(promise.__proto__, [
'then',
'catch'
]);
gapi.client.load = delegate; // Remove the Promise patch;
return promise;
}
})(gapi.client.load);
}