Skip to content

Commit

Permalink
avoid executing tokens that are null
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Aug 2, 2018
1 parent 138605e commit 528ddaf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 7 additions & 7 deletions packages/electrode-react-webapp/lib/react/token-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module.exports = function setup(handlerContext /* , asyncTemplate */) {
return result;
};

const beforeRender = async context => {
const INITIALIZE = async context => {
const options = context.options;
const request = options.request;
const mode = options.mode;
Expand Down Expand Up @@ -253,12 +253,12 @@ module.exports = function setup(handlerContext /* , asyncTemplate */) {
return criticalCSS ? `<style${context.user.styleNonce}>${criticalCSS}</style>` : "";
},

INITIALIZE: beforeRender,
HEAD_INITIALIZE: _.noop,
HEAD_CLOSED: _.noop,
AFTER_SSR_CONTENT: _.noop,
BODY_CLOSED: _.noop,
HTML_CLOSED: _.noop
INITIALIZE,
HEAD_INITIALIZE: null,
HEAD_CLOSED: null,
AFTER_SSR_CONTENT: null,
BODY_CLOSED: null,
HTML_CLOSED: null
};

return {
Expand Down
8 changes: 7 additions & 1 deletion packages/electrode-react-webapp/lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class Renderer {

const tkFunc = handler.tokens[tk.id];

if (tkFunc === null) {
return null;
}

// not a function, just add it to output
if (typeof tkFunc !== "function") {
return xt => {
Expand Down Expand Up @@ -67,7 +71,9 @@ class Renderer {
xt.context.handleTokenResult(tk.id, tk.process(xt.context), err => this._next(err, xt));
};

this.renderSteps = options.htmlTokens.map(tk => ({ tk, exec: makeStep(tk) }));
this.renderSteps = options.htmlTokens
.map(tk => ({ tk, exec: makeStep(tk) }))
.filter(x => x.exec);
}

render(context) {
Expand Down

0 comments on commit 528ddaf

Please sign in to comment.