Skip to content

Commit

Permalink
Wait for state from /now before rendering (#649)
Browse files Browse the repository at this point in the history
* Wait for state from /now before rendering

* Move initialization code from index.html → app.js

* fixup! Move initialization code from index.html → app.js
  • Loading branch information
goto-bus-stop authored May 25, 2017
1 parent 3de7d0a commit 2421a7a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/Uwave.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export default class Uwave {
constructor(options = {}, session = readSession()) {
this.options = options;
this.jwt = session;
this.ready = new Promise((resolve) => {
this.resolveReady = resolve;
});

Object.assign(this, api.constants);
Object.assign(this, api.components);
Expand Down Expand Up @@ -91,7 +94,9 @@ export default class Uwave {
}

this.store.dispatch(socketConnect());
this.store.dispatch(initState());
return this.store.dispatch(initState()).then(() => {
this.resolveReady();
});
}

getComponent() {
Expand Down
7 changes: 7 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ uw.source('youtube', youTubeSource);
uw.source('soundcloud', soundCloudSource);

window.uw = uw;

uw.build().then(() => {
uw.renderToDOM(document.querySelector('#app'));
document.querySelector('#app-loading').innerHTML = '';
}).catch((err) => {
document.querySelector('.LoadingScreen-notice').textContent = `Error: ${err.message}`;
});
4 changes: 0 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,5 @@
<% for (const chunk in htmlWebpackPlugin.files.chunks) { %>
<script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>"></script>
<% } %>
<script>
uw.renderToDOM(document.querySelector('#app'));
document.querySelector('#app-loading').innerHTML = '';
</script>
</body>
</html>

0 comments on commit 2421a7a

Please sign in to comment.