Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed zone.js #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions components/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as ng from 'angular2/angular2';
import {LifeCycle} from 'angular2/src/core/life_cycle/life_cycle';
import {Video} from 'components/video';
import {YoutubeService} from 'services/youtube';

Expand All @@ -13,13 +12,9 @@ import {YoutubeService} from 'services/youtube';
})
export class YoutubeApp {
videos;
constructor(lc: LifeCycle, yt: YoutubeService) {
constructor(yt: YoutubeService) {
this.videos = [];
this.lc = lc;
yt.init().then((videos) => {
this.videos = videos;
lc.tick(); // investigate why needed?
});
yt.init().then((videos) => this.videos = videos);
}
}

25 changes: 25 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,34 @@
<youtube-app>Loading... Please wait</youtube-app>
<script>
System.import('main').then(function(module) {
zone = zone.fork(Zone.longStackTraceZone);
module.main();
}, console.log.bind(console));
</script>
<script type="text/javascript">
function googleClientReady() {
/**
* 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);
Zone.patchPrototype(promise.__proto__, [
'then',
'catch'
]);
gapi.client.load = delegate; // Remove the Promise patch;
return promise;
}
})(gapi.client.load);
}
</script>
<script src="https://apis.google.com/js/client.js?onload=googleClientReady"></script>
</body>
</html>
Expand Down