Skip to content

Commit

Permalink
Rollback Template Optimization - It works fine for templating, but no…
Browse files Browse the repository at this point in the history
…t for dom acessing inside scripts.
Javiani committed Apr 28, 2024
1 parent a893aa0 commit a914b78
Showing 5 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/jails.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jails.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jails-js",
"version": "5.7.0",
"version": "5.7.1",
"description": "Jails - Elegant and Minimalistic Javascript Application Library",
"module": "./dist/jails.js",
"main": "./dist/jails.js",
8 changes: 4 additions & 4 deletions src/template-system.ts
Original file line number Diff line number Diff line change
@@ -9,9 +9,9 @@ export const templateConfig = (newconfig) => {
Object.assign(config, newconfig)
}

export default function Template(element, components) {
export default function Template(element) {

const html = Transpile(element.outerHTML, config, components, element)
const html = Transpile(element.outerHTML, config)
const decodedHTML = JSON.stringify(html)

return new Function('$element', 'safe',`
@@ -54,13 +54,13 @@ const createTemplateId = (element, templates, components ) => {
element.__template = html
html.then( htmlstring => {
element.innerHTML = htmlstring
templates[id] = Template(element, components)
templates[id] = Template(element)
})
}else {
element.innerHTML = html
}
}
templates[id] = Template(element, components)
templates[id] = Template(element)
}
}

10 changes: 1 addition & 9 deletions src/transpile.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
const parser = new DOMParser()

export default function Transpile(html, config, components, element) {
export default function Transpile(html, config) {

const regexTags = new RegExp(`\\${config.tags[0]}(.+?)\\${config.tags[1]}`, 'g')
const virtual = parser.parseFromString(html.replace(/<\/?template[^>]*>/g, ''), 'text/html')

const root = virtual.querySelector(element.localName)
const childNodes = Object.keys(components).toString()

root.querySelectorAll(childNodes).forEach( node => {
const clone = node.cloneNode()
node.replaceWith(clone)
})

virtual.querySelectorAll('[html-for], [html-if], [html-inner], [html-class], [html-model]').forEach((element) => {

const htmlForeach = element.getAttribute('html-foreach')

0 comments on commit a914b78

Please sign in to comment.