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

Revert "Revert "[major] Load CSS first and render instantly when the CSS... #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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