Skip to content

Commit becc242

Browse files
committed
Minor refactor to decouple Template internals from TemplateMap
1 parent a65005b commit becc242

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/TemplateContent.js

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ class TemplateContent {
3636
this.inputPath = inputPath;
3737
}
3838

39+
async asyncTemplateInitialization() {
40+
if (!this.hasTemplateRender()) {
41+
await this.getTemplateRender();
42+
}
43+
}
44+
3945
resetCachedTemplate({ eleventyConfig }) {
4046
this.eleventyConfig = eleventyConfig;
4147
}

src/TemplateMap.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,16 @@ class TemplateMap {
149149

150150
// TODO(slightlyoff): major bottleneck
151151
async initDependencyMap(dependencyMap) {
152-
// Temporary workaround for `templateRender` sync references
152+
// Temporary workaround for async constructor work in templates
153153
let inputPathSet = new Set(dependencyMap);
154154
await Promise.all(
155-
this.map.map(({ inputPath, template }) => {
156-
if (inputPathSet.has(inputPath)) {
157-
return template.getTemplateRender();
158-
}
159-
}),
155+
this.map
156+
.filter(({ inputPath }) => {
157+
return inputPathSet.has(inputPath);
158+
})
159+
.map(({ template }) => {
160+
return template.asyncTemplateInitialization();
161+
}),
160162
);
161163

162164
for (let depEntry of dependencyMap) {

0 commit comments

Comments
 (0)