-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More Performant Templates Clonning (#3)
* simple cloneNode(true) * optimization for exactly same and static elements * fix typo * using helper function to create iife * impove tests perf * fix tests
- Loading branch information
Showing
20 changed files
with
141 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,6 +129,8 @@ function post(file) { | |
} else { | ||
produceImports(); | ||
} | ||
|
||
shared.set("sharedNodes", {}); | ||
} | ||
|
||
export { post }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { shared } from "../shared"; | ||
|
||
/** | ||
* | ||
* @param {...babel.types.Statement} body | ||
* @returns | ||
*/ | ||
const createIIFE = (...body) => { | ||
const { types: t } = shared().babel; | ||
|
||
return t.callExpression(t.arrowFunctionExpression([], t.blockStatement(body)), []); | ||
}; | ||
|
||
export { createIIFE }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { template as _tmpl } from "grim-jsx/runtime.js"; | ||
import { template as _template } from "grim-jsx/runtime.js"; | ||
import styles from './styles.module.css'; | ||
|
||
const Paragraph = ({ | ||
children | ||
}) => { | ||
const p = _tmpl(`<p class="${styles.paragraph}">${children}</p>`); | ||
const p = _template(`<p class="${styles.paragraph}">${children}</p>`); | ||
|
||
return p; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { template as _tmpl } from "grim-jsx/runtime.js"; | ||
import { template as _template } from "grim-jsx/runtime.js"; | ||
|
||
const As = props => { | ||
const el = _tmpl(`<${props.as}></${props.as}>`); | ||
const el = _template(`<${props.as}></${props.as}>`); | ||
|
||
return el; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { template as _tmpl, spread as _sprd } from "grim-jsx/runtime.js"; | ||
import { template as _template, spread as _sprd } from "grim-jsx/runtime.js"; | ||
|
||
const div = _tmpl(`<div style="color:red;">Hello</div>`); | ||
let _tmpl = _template(`<div style="color:red;">Hello</div>`); | ||
|
||
const div = _tmpl.cloneNode(true); | ||
|
||
let key = window.style_key; | ||
let value = window.style_value(); | ||
const elements = [_tmpl(`<span style="${_sprd({ | ||
const elements = [_template(`<span style="${_sprd({ | ||
[key]: value | ||
}, true)}">Hello</span>`), _tmpl(`<span style="${_sprd({ | ||
}, true)}">Hello</span>`), _template(`<span style="${_sprd({ | ||
[window.style_key]: window.style_value() | ||
}, true)}">Hello</span>`)]; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { template as _tmpl, spread as _sprd } from "grim-jsx/runtime.js"; | ||
import { template as _template, spread as _sprd } from "grim-jsx/runtime.js"; | ||
|
||
const Component = props => _tmpl(`<div ${_sprd(props)}></div>`); | ||
const Component = props => _template(`<div ${_sprd(props)}></div>`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import { template as _tmpl } from "grim-jsx/runtime.js"; | ||
import { template as _template } from "grim-jsx/runtime.js"; | ||
|
||
let _tmpl = _template(`<div></div>`); | ||
|
||
const people = ["Artem", "Ivan", "Arina", "Roman", "Kenzi"]; | ||
let str = `<div><h1>Hello!</h1><ul>${people.map(person => `<li>${person}</li>`).join("")}</ul></div>`; | ||
|
||
const node = _tmpl(`<div></div>`); | ||
const node = _tmpl.cloneNode(true); | ||
|
||
str = `<div>It should be a string</div>`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import { template as _tmpl } from "grim-jsx/runtime.js"; | ||
import { template as _template } from "grim-jsx/runtime.js"; | ||
|
||
const icon = _tmpl(`<svg width="24" height="24" fill="none" viewBox="0 0 24 24"></svg>`); | ||
let _tmpl2 = _template(`<svg><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M18.25 12.25L5.75 12.25"></path></svg>`, true); | ||
|
||
const path = _tmpl(`<svg><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M18.25 12.25L5.75 12.25"></path></svg>`, true); | ||
let _tmpl = _template(`<svg width="24" height="24" fill="none" viewBox="0 0 24 24"></svg>`); | ||
|
||
const icon = _tmpl.cloneNode(true); | ||
|
||
const path = _tmpl2.cloneNode(true); | ||
|
||
icon.appendChild(path); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
import { template as _tmpl, firstElementChild as _fec, nextElementSibling as _nes } from "grim-jsx/runtime.js"; | ||
import { template as _template, firstElementChild as _fec, nextElementSibling as _nes } from "grim-jsx/runtime.js"; | ||
|
||
let _tmpl2 = _template(`<footer><p>Copyright © 2069</p></footer>`); | ||
|
||
let _tmpl = _template(`<article><h1>Hello!</h1><p>Today we are going to find out something</p><button>Find out!</button></article>`); | ||
|
||
let button; | ||
|
||
const article = (() => { | ||
const tmpl = _tmpl(`<article><h1>Hello!</h1><p>Today we are going to find out something</p><button>Find out!</button></article>`); | ||
const _el = _tmpl.cloneNode(true); | ||
|
||
button = tmpl[_fec][_nes][_nes]; | ||
return tmpl; | ||
button = _el[_fec][_nes][_nes]; | ||
return _el; | ||
})(); | ||
|
||
let foo; | ||
|
||
const footer = (() => { | ||
const tmpl = _tmpl(`<footer><p>Copyright © 2069</p></footer>`); | ||
const _el2 = _tmpl2.cloneNode(true); | ||
|
||
foo = tmpl; | ||
return tmpl; | ||
foo = _el2; | ||
return _el2; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { template as _tmpl2, firstElementChild as _fec, nextElementSibling as _nes } from "grim-jsx/runtime.js"; | ||
let _tmpl = 'Noodles'; | ||
import { template as _template2, firstElementChild as _fec, nextElementSibling as _nes } from "grim-jsx/runtime.js"; | ||
let _template = 'Noodles'; | ||
let eggs; | ||
|
||
const list = (() => { | ||
const tmpl = _tmpl2(`<ul><li>${_tmpl}</li><li>Soup</li><li>Rice</li><li>Eggs</li></ul>`); | ||
const _el = _template2(`<ul><li>${_template}</li><li>Soup</li><li>Rice</li><li>Eggs</li></ul>`); | ||
|
||
eggs = tmpl[_fec][_nes][_nes][_nes]; | ||
return tmpl; | ||
eggs = _el[_fec][_nes][_nes][_nes]; | ||
return _el; | ||
})(); |