Skip to content

Commit

Permalink
Merge pull request #16 from a-ignatov-parc/bugfix
Browse files Browse the repository at this point in the history
Fix for sub renders after dismissed document
  • Loading branch information
a-ignatov-parc authored Nov 27, 2017
2 parents a5defa2 + 35832a7 commit b6ba674
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -75,6 +84,17 @@ export function render(template) {
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];
Expand All @@ -100,9 +120,6 @@ export function render(template) {
menuBar.setDocument(document, menuItem);
}, RENDERING_ANIMATION);
}
} else if (possiblyDismissedByUser) {
// 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 {
Expand Down

0 comments on commit b6ba674

Please sign in to comment.