From 436cd166747b4712fd56d456503b49da560f2099 Mon Sep 17 00:00:00 2001 From: Roman Karpov Date: Thu, 13 May 2021 11:38:18 +0300 Subject: [PATCH] feat (individual presenter): add support for external .html templates --- source-web/js/common/backend.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/source-web/js/common/backend.js b/source-web/js/common/backend.js index ff3a47be3..47ce3e2c2 100644 --- a/source-web/js/common/backend.js +++ b/source-web/js/common/backend.js @@ -892,7 +892,21 @@ browserBackend.uploadFile = function (params, tries) { }); }; -browserBackend.loadFile = function (url) { +const memoize = (fn) => { + const cache = {}; + return (...args) => { + const n = args[0]; + if (n in cache) { + return cache[n]; + } else { + const result = fn(n); + cache[n] = result; + return result; + } + }; +}; + +browserBackend.loadFile = memoize(function (url) { return new Promise(function (resolve, reject) { const done = () => { if (xhr.status === 200) { @@ -913,7 +927,7 @@ browserBackend.loadFile = function (url) { xhr.ontimeout = fail; xhr.send(); }); -}; +}); // //////////////////////////////////////////////////////////////////////