Skip to content

Commit

Permalink
Merge pull request #61 from lukebayes/client
Browse files Browse the repository at this point in the history
Fixed example client initialization
  • Loading branch information
lukebayes committed Apr 19, 2017
2 parents 14f21b6 + b5f03ba commit f64b25f
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions examples/client/client.js
@@ -1,4 +1,5 @@
const dom = require('../../').dom;
const ready = require('../../').ready;
const renderElement = require('../../').renderElement;

const DOM_CONTENT_LOADED = 'DOMContentLoaded';
Expand All @@ -7,17 +8,12 @@ function client(doc) {
// Render the application immediately. This can begin before the DOM is fully ready.
const app = renderElement(dom.h1('HELLO WORLD 34343'), doc);

function contentLoadedHandler() {
ready(doc, () => {
// Get the element where we will attach the application.
const context = doc.getElementById('context');
// Attach the application.
context.appendChild(app);
// Clean up this dangling listener.
doc.removeEventListener(DOM_CONTENT_LOADED, contentLoadedHandler);
};

// Wait until the DOM is ready (works in IE9+ and all others?)
doc.addEventListener(DOM_CONTENT_LOADED, contentLoadedHandler);
});
}

module.exports = client;
Expand Down

0 comments on commit f64b25f

Please sign in to comment.