Avoid computation of code blocks search in template if no callback

This commit is contained in:
Niko 2022-02-23 20:00:14 +01:00
parent 36151c128c
commit 27eefb7da3
1 changed files with 4 additions and 5 deletions

View File

@ -50,6 +50,7 @@ app.template = {
if (typeof data === 'string') if (typeof data === 'string')
data = { value: data }; data = { value: data };
(function() { (function() {
if (customCback === undefined) return;
const res = tpl.match(/\{loop([^\{\}]+)?\}[.\s\S]+?{\/loop\}/g); const res = tpl.match(/\{loop([^\{\}]+)?\}[.\s\S]+?{\/loop\}/g);
if (res === null) return; if (res === null) return;
for (var i = 0; i < res.length; i++) { for (var i = 0; i < res.length; i++) {
@ -59,11 +60,9 @@ app.template = {
cnt = cnt.substr(0, cnt.lastIndexOf('{')).trim(); cnt = cnt.substr(0, cnt.lastIndexOf('{')).trim();
var k = res[i].trim(); var k = res[i].trim();
k = k.substr(1, k.indexOf('}')-1).trim(); k = k.substr(1, k.indexOf('}')-1).trim();
if (customCback !== undefined) { var newv = customCback(k, cnt);
var newv = customCback(k, cnt); if (typeof newv === 'string')
if (typeof newv === 'string') tpl = tpl.replace(original, newv);
tpl = tpl.replace(original, newv);
}
} }
})(); })();
(function() { (function() {