Skip to content

Instantly share code, notes, and snippets.

@peschee
Forked from andyvanee/tagProps.js
Created August 13, 2020 06:43
Show Gist options
  • Save peschee/d24754802b8791f6f76ce3129122dbea to your computer and use it in GitHub Desktop.
Save peschee/d24754802b8791f6f76ce3129122dbea to your computer and use it in GitHub Desktop.
tagProps lit-element directive
import { directive } from "https://unpkg.com/@polymer/lit-element/lit-element.js?module"
const stateMap = new WeakMap()
export const tagProps = directive((tag, props = {}) => part => {
let state = stateMap.get(part)
const el = () => document.createElement(tag)
if (state === undefined) {
state = { tag, element: el() }
stateMap.set(part, state)
}
if (state.tag != tag) {
state.element = el()
stateMap.set(part, state)
}
Object.assign(state.element, props)
part.setValue(state.element)
})
@peschee
Copy link
Author

peschee commented Aug 13, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment