-
-
Save peschee/d24754802b8791f6f76ce3129122dbea to your computer and use it in GitHub Desktop.
tagProps lit-element directive
This file contains hidden or 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 { 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) | |
}) |
Author
peschee
commented
Aug 13, 2020
- lit/lit#78 (comment)
- https://codepen.io/andyvanee/pen/jOqWWge
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment