From 507c545c6d5dca42c413ba3a0d8b0d2d049fff8a Mon Sep 17 00:00:00 2001 From: Lcfvs Date: Thu, 1 Jul 2021 18:26:39 +0200 Subject: [PATCH] + perfs improvements --- lib/dom.js | 12 +++++++++--- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/dom.js b/lib/dom.js index 7b342d0..5d67f5d 100644 --- a/lib/dom.js +++ b/lib/dom.js @@ -38,7 +38,7 @@ const tokenize = node => { for (const { name, value } of current.attributes) { const tokens = identify(value) - if (tokens) { + if (tokens.length) { attributes.set(name, tokens) } } @@ -141,9 +141,15 @@ const fill = template => { } const value = (tokens, node, name, template) => { + const { length } = tokens + + if (!length) { + return + } + let value = node.getAttribute(name) - if (tokens.length === 1) { + if (length === 1) { const [{ key, optional }] = tokens value = resolve(key, optional, template) @@ -179,7 +185,7 @@ const content = (tokens, node, template) => { const value = resolve(key, optional, template) const replacements = Array.isArray(value) ? value - : value && value[Symbol.iterator] + : value && typeof value === 'object' && value[Symbol.iterator] ? [...new Map(value).values()] : [value] diff --git a/package-lock.json b/package-lock.json index 21bcde2..c7565c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@lcf.vs/dom-engine", - "version": "3.1.1", + "version": "4.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@lcf.vs/dom-engine", - "version": "3.1.1", + "version": "4.0.1", "license": "MIT", "dependencies": { "jsdom": "^16.6.0" diff --git a/package.json b/package.json index 6a1766e..82c4d01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lcf.vs/dom-engine", - "version": "4.0.0", + "version": "4.0.1", "description": "A composable DOM based template engine", "type": "module", "scripts": {