Skip to content

Commit

Permalink
avoid setting the context unless actually necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbmeyer committed Jun 20, 2018
1 parent 1d8cbbe commit 3182889
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"can-assign": "^1.1.1",
"can-attribute-encoder": "^1.0.0",
"can-child-nodes": "^1.0.0",
"can-define-lazy-value": "^1.0.2",
"can-dom-data": "^1.0.1",
"can-dom-data-state": "^1.0.0",
"can-dom-mutate": "^1.0.0",
Expand Down
22 changes: 14 additions & 8 deletions src/mustache_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ var canSymbol = require("can-symbol");
var canReflect = require("can-reflect");
var dev = require("can-log/dev/dev");
var getDocument = require("can-globals/document/document");
var defineLazyValue = require("can-define-lazy-value");

// Lazily lookup the context only if it's needed.
function HelperOptions(scope, nodeList, exprData, stringOnly) {
this.metadata = { rendered: false };
this.stringOnly = stringOnly;
this.scope = scope;
this.nodeList = nodeList;
this.exprData = exprData;
}
defineLazyValue(HelperOptions.prototype,"context", function(){
return this.scope.peek("this");
});

// ## Types

Expand Down Expand Up @@ -63,14 +76,7 @@ var core = {
}

var value,
helperOptions = {
metadata: { rendered: false },
stringOnly: stringOnly,
context: scope.peek("this"),
scope: scope,
nodeList: nodeList,
exprData: exprData
};
helperOptions = new HelperOptions(scope, nodeList, exprData, stringOnly);
// set up renderers
utils.createRenderers(helperOptions, scope, nodeList, truthyRenderer, falseyRenderer, stringOnly);

Expand Down

0 comments on commit 3182889

Please sign in to comment.