Template renderer internal data update (#1764)

* Add cleanup callbacks

* Move requirements

* Add custom data
This commit is contained in:
toasted-nutbread 2021-06-26 17:43:07 -04:00 committed by GitHub
parent 73caeac0fb
commit 8eb9c94f8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,6 +29,8 @@ class TemplateRenderer {
this._stateStack = null;
this._dataTypes = new Map();
this._requirements = null;
this._cleanupCallbacks = null;
this._customData = null;
}
registerDataType(name, {modifier=null, composeData=null}) {
@ -85,15 +87,21 @@ class TemplateRenderer {
}
_renderTemplate(instance, data) {
const cleanupCallbacks = [];
const requirements = [];
try {
const requirements = [];
this._customData = {};
this._stateStack = [new Map()];
this._requirements = requirements;
this._cleanupCallbacks = cleanupCallbacks;
const result = instance(data).trim();
return {result, requirements};
} finally {
for (const callback of cleanupCallbacks) { callback(); }
this._stateStack = null;
this._requirements = null;
this._cleanupCallbacks = null;
this._customData = null;
}
}