Fix issue with tracking components for client-reorder await tags

This commit is contained in:
Dylan Piercey 2019-07-03 10:14:28 -07:00
parent 535daf9451
commit 6e236c8f02
No known key found for this signature in database
GPG Key ID: DA54E25D5BF13DBE
5 changed files with 30 additions and 35 deletions

View File

@ -109,10 +109,10 @@ class Node {
*/
makeContainer(array) {
if (array instanceof Container) {
return array;
}
if (!Array.isArray(array) && array instanceof Node) {
const container = array;
array = container.items;
container.items = [];
} else if (!Array.isArray(array) && array instanceof Node) {
array = [array];
}

View File

@ -5,17 +5,6 @@ const INIT_COMPONENTS_KEY = Symbol();
const writeInitComponentsCode = require("../../runtime/components")
.writeInitComponentsCode;
const ComponentsContext = require("../../runtime/components/ComponentsContext");
function handleAwaitBeforeRender(eventArgs) {
if (eventArgs.clientReorder) {
const asyncFragmentOut = eventArgs.out;
asyncFragmentOut.___components = new ComponentsContext(
asyncFragmentOut
);
}
}
function handleAwaitFinish(eventArgs) {
const asyncFragmentOut = eventArgs.out;
writeInitComponentsCode(asyncFragmentOut, asyncFragmentOut, false);
@ -26,7 +15,6 @@ module.exports = function render(input, out) {
if (outGlobal[INIT_COMPONENTS_KEY] === undefined) {
outGlobal[INIT_COMPONENTS_KEY] = true;
out.on("await:beforeRender", handleAwaitBeforeRender);
out.on("await:finish", handleAwaitFinish);
if (out.isSync() === true) {

View File

@ -5,25 +5,18 @@ var componentLookup = componentsUtil.___componentLookup;
var registry = require("../registry");
var modernRenderer = require("../renderer");
var resolveComponentKey = modernRenderer.___resolveComponentKey;
var handleBeginAsync = modernRenderer.___handleBeginAsync;
var trackAsyncComponents = modernRenderer.___trackAsyncComponents;
var beginComponent = require("../beginComponent");
var endComponent = require("../endComponent");
var w10NOOP = require("warp10/constants").NOOP;
var WIDGETS_BEGIN_ASYNC_ADDED_KEY = "$wa";
function createRendererFunc(templateRenderFunc, componentProps) {
var typeName = componentProps.___type;
//var assignedId = componentProps.id;
var isSplit = componentProps.___split === true;
return function renderer(input, out, assignedId, renderingLogic) {
var outGlobal = out.global;
if (!outGlobal[WIDGETS_BEGIN_ASYNC_ADDED_KEY]) {
outGlobal[WIDGETS_BEGIN_ASYNC_ADDED_KEY] = true;
out.on("beginAsync", handleBeginAsync);
}
trackAsyncComponents(out);
var widgetBody = input.renderBody;
var widgetState = input.widgetState;

View File

@ -20,6 +20,16 @@ function resolveComponentKey(key, parentComponentDef) {
}
}
function trackAsyncComponents(out) {
if (out.isSync() || out.global[COMPONENT_BEGIN_ASYNC_ADDED_KEY]) {
return;
}
out.on("beginAsync", handleBeginAsync);
out.on("beginDetachedAsync", handleBeginDetachedAsync);
out.global[COMPONENT_BEGIN_ASYNC_ADDED_KEY] = true;
}
function handleBeginAsync(event) {
var parentOut = event.parentOut;
var asyncOut = event.out;
@ -40,6 +50,13 @@ function handleBeginAsync(event) {
);
}
function handleBeginDetachedAsync(event) {
var asyncOut = event.out;
handleBeginAsync(event);
asyncOut.on("beginAsync", handleBeginAsync);
asyncOut.on("beginDetachedAsync", handleBeginDetachedAsync);
}
function createRendererFunc(
templateRenderFunc,
componentProps,
@ -54,14 +71,7 @@ function createRendererFunc(
var shouldApplySplitMixins = isSplit;
return function renderer(input, out) {
var outGlobal = out.global;
if (out.isSync() === false) {
if (!outGlobal[COMPONENT_BEGIN_ASYNC_ADDED_KEY]) {
outGlobal[COMPONENT_BEGIN_ASYNC_ADDED_KEY] = true;
out.on("beginAsync", handleBeginAsync);
}
}
trackAsyncComponents(out);
var componentsContext = getComponentsContext(out);
var globalComponentsContext = componentsContext.___globalContext;
@ -196,7 +206,7 @@ function createRendererFunc(
}
}
component.___global = outGlobal;
component.___global = out.global;
emitLifecycleEvent(component, "render", out);
}
@ -231,4 +241,4 @@ module.exports = createRendererFunc;
// exports used by the legacy renderer
createRendererFunc.___resolveComponentKey = resolveComponentKey;
createRendererFunc.___handleBeginAsync = handleBeginAsync;
createRendererFunc.___trackAsyncComponents = trackAsyncComponents;

View File

@ -469,6 +469,10 @@ var proto = (AsyncStream.prototype = {
var newOut = new AsyncStream(this.global);
// Forward error events to the parent out.
newOut.on("error", this.emit.bind(this, "error"));
this._state.events.emit("beginDetachedAsync", {
out: newOut,
parentOut: this
});
return newOut;
},