Skip to content
Open
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
37 changes: 22 additions & 15 deletions pagelet.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,27 +160,34 @@ Pagelet.prototype.configure = function configure(name, data, roots) {
//
pagelet.broadcast('configured', data);

async.each(this.css.concat(this.js), function download(url, next) {
async.each(pagelet.css, function download(url, next) {
assets.add(url, next);
}, function done(err) {
if (err) return pagelet.broadcast('error', err);

pagelet.broadcast('loaded');
pagelet.render(pagelet.parse());

//
// All resources are loaded, but we have a parent element. When the parent
// element renders it will most likely also nuke our placeholder references
// preventing us from rendering updates again.
//
if (parent) parent.on('render', function render() {
pagelet.placeholders = pagelet.$('data-pagelet', pagelet.name, parent.placeholders);
pagelet.listen();
pagelet.render(pagelet.data || pagelet.parse());
});

pagelet.initialize();
}, { context: this.bigpipe, timeout: this.timeout });
async.each(pagelet.js, function download(url, next) {
assets.add(url, next);
}, function done(err) {
//
// All resources are loaded, but we have a parent element. When the parent
// element renders it will most likely also nuke our placeholder references
// preventing us from rendering updates again.
//
// @TODO we need a pre-render event so we can clear assigned event
// listeners.
//
if (parent) parent.on('render', function render() {
pagelet.placeholders = pagelet.$('data-pagelet', pagelet.name, parent.placeholders);
pagelet.listen();
pagelet.render(pagelet.data || pagelet.parse());
});

pagelet.broadcast('loaded');
pagelet.initialize();
}, { timeout: pagelet.timeout });
}, { timeout: pagelet.timeout });
};

/**
Expand Down