From 30ad713ff0062d50cdf360f6121a1e32a4d7f371 Mon Sep 17 00:00:00 2001 From: Anton Ignatov Date: Mon, 27 Nov 2017 01:16:32 +0300 Subject: [PATCH 1/2] Fix for subrenders after dismissed document --- src/render.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/render.js b/src/render.js index 74a66e9..b2ebc37 100644 --- a/src/render.js +++ b/src/render.js @@ -67,10 +67,12 @@ export function render(template) { route, redirect, navigation = {}, - parsedDocument: document, } = payload; - let { document: renderedDocument } = payload; + let { + parsedDocument: document, + document: renderedDocument, + } = payload; const { menuBar, menuItem } = navigation; const { possiblyDismissedByUser } = renderedDocument || {}; @@ -101,6 +103,12 @@ export function render(template) { }, RENDERING_ANIMATION); } } else if (possiblyDismissedByUser) { + /** + * Because this stage should be noop we need to restore last + * rendered document. + */ + document = payload.renderedDocument; + // eslint-disable-next-line max-len console.warn('Rendering pipeline was terminated by user. Skipping further renders...'); } else if (renderedDocument) { @@ -109,7 +117,10 @@ export function render(template) { navigationDocument.pushDocument(document); } - return { document, redirect: false }; + return { + document, + redirect: false, + }; })) .pipe(passthrough(() => promisedTimeout(RENDERING_ANIMATION))); } From 35832a7863f488e4e5f99f5e1b562f150b574c02 Mon Sep 17 00:00:00 2001 From: Anton Ignatov Date: Mon, 27 Nov 2017 11:04:46 +0300 Subject: [PATCH 2/2] Fixed possible edge cases for canceled pipelines --- src/render.js | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/render.js b/src/render.js index b2ebc37..3bab971 100644 --- a/src/render.js +++ b/src/render.js @@ -26,9 +26,18 @@ function createDocument(template, payload) { } export function parseDocument(template) { - return createPipeline().pipe(passthrough(payload => ({ - parsedDocument: createDocument(template, payload), - }))); + return createPipeline().pipe(passthrough((payload) => { + const { possiblyDismissedByUser } = (payload || {}).renderedDocument || {}; + + let parsedDocument = null; + + // We don't want to process documents in canceled pipeline. + if (!possiblyDismissedByUser) { + parsedDocument = createDocument(template, payload); + } + + return { parsedDocument }; + })); } export function removeModal() { @@ -67,16 +76,25 @@ export function render(template) { route, redirect, navigation = {}, - } = payload; - - let { parsedDocument: document, - document: renderedDocument, } = payload; + let { document: renderedDocument } = payload; + const { menuBar, menuItem } = navigation; const { possiblyDismissedByUser } = renderedDocument || {}; + /** + * If we received dismissed document it means that user pressed menu + * button and our pipeline is canceled. Now we must silently succeed + * the rest of the pipeline without rendering anything. + */ + if (possiblyDismissedByUser) { + // eslint-disable-next-line max-len + console.warn('Rendering pipeline was canceled by user. Skipping further renders...'); + return null; + } + const prevRouteDocument = renderedDocument ? renderedDocument.prevRouteDocument : navigationDocument.documents.slice(-1)[0]; @@ -102,25 +120,13 @@ export function render(template) { menuBar.setDocument(document, menuItem); }, RENDERING_ANIMATION); } - } else if (possiblyDismissedByUser) { - /** - * Because this stage should be noop we need to restore last - * rendered document. - */ - document = payload.renderedDocument; - - // eslint-disable-next-line max-len - console.warn('Rendering pipeline was terminated by user. Skipping further renders...'); } else if (renderedDocument) { navigationDocument.replaceDocument(document, renderedDocument); } else { navigationDocument.pushDocument(document); } - return { - document, - redirect: false, - }; + return { document, redirect: false }; })) .pipe(passthrough(() => promisedTimeout(RENDERING_ANIMATION))); }