From 8eb9c94f8a651a702347454fee9512f34bd44cb4 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 26 Jun 2021 17:43:07 -0400 Subject: Template renderer internal data update (#1764) * Add cleanup callbacks * Move requirements * Add custom data --- ext/js/templates/template-renderer.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'ext') diff --git a/ext/js/templates/template-renderer.js b/ext/js/templates/template-renderer.js index e27ad03c..a06298aa 100644 --- a/ext/js/templates/template-renderer.js +++ b/ext/js/templates/template-renderer.js @@ -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; } } -- cgit v1.2.3