Created
September 26, 2018 10:11
-
-
Save AStaroverov/338e63fddc4d1e7783515f0934c4b492 to your computer and use it in GitHub Desktop.
lit-html with dynamic tags
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
import { html } from '@polymer/lit-element/src/lit-element'; | |
let string: string; | |
let valuesLength: number; | |
export function preHTML (strings: TemplateStringsArray, ...values: any[]) { | |
const newStrings: string[] = []; | |
const newValues: any[] = []; | |
valuesLength = values.length; | |
for (var i = 0; i < strings.length; i += 1) { | |
string = strings[i]; | |
if (string[string.length - 1] === '<') { | |
newStrings.push(string + values[i] + strings[++i]); | |
newValues.push(values[i]); | |
} else if (string[string.length - 2] === '<' && string[string.length - 1] === '/') { | |
newStrings.push((string = string + values[i] + strings[++i])); | |
} else { | |
newStrings.push(string); | |
newValues.push(values[i]); | |
} | |
} | |
return html(newStrings as any, ...newValues); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment