Skip to content
Open
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
33 changes: 23 additions & 10 deletions src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,35 @@ function processChildren(stream, children, options, callback) {
continue;
}

let _callback = function() {
let res = callback.apply(null, arguments);
let next = i + 1;
if(next < children.length) {
let remainder = children.slice(next);
if(nonBlocking) {
process.nextTick(_ =>
processChildren(stream, remainder, options, callback));
} else {
processChildren(stream, remainder, options, callback);
}
}
return res;
};

let { nonBlocking, log, _idRegistry } = options;
let generatorOptions = { nonBlocking, log, _idRegistry };
if(child.length !== 1) { // element generator -- XXX: brittle heuristic (arity)
child(stream, generatorOptions, callback);
continue;
if(nonBlocking) {
child(stream, generatorOptions, _callback);
break;
} else {
child(stream, generatorOptions, callback);
continue;
}
}

// deferred child element
let fn = element => {
element(stream, generatorOptions, callback);
let next = i + 1;
if(next < children.length) {
let remainder = children.slice(next);
processChildren(stream, remainder, options, callback);
}
};
let fn = element => element(stream, generatorOptions, _callback);

if(!nonBlocking) { // ensure deferred child element is synchronous
let invoked = false;
Expand Down
12 changes: 12 additions & 0 deletions test/test_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ describe("renderer", _ => {
done();
});

it("should support non-blocking mode", done => {
let { renderer, stream } = setup();

/* eslint-disable indent */
renderer.renderView(NonBlockingContainer, null, stream, { fragment: true }, _ => {
assert.equal(stream.read(),
"<div><p>…</p><p><i>lorem ipsum</i></p><p>…</p></div>");
done();
});
/* eslint-enable indent */
});

it("should detect non-blocking child elements in blocking mode", done => {
let { renderer, stream } = setup();

Expand Down