ref-to
v0.0.8
Published
ref-to is a web component that dynamically generates another web component, that it stays connect with.
Downloads
6
Maintainers
Readme
ref-to
ref-to is a web component. Sample syntax:
<ref-to a=my-grid id=myRefTo></ref-to>
What ref-to does:
- Attribute "a" (or "an") is expected to be the name of a built-in element, or satisfy custom-element/web-component naming conventions.
- It does document.createElement('my-grid') (in this example) and creates a weak reference to it. The actual element can be retrieved, if it still exists: myRefTo.deref. ref-to does not add the element to any live DOM tree.
- ref-to searches direct children for text nodes and ref-to children. In the case of rev-to's, adds reference to children of its reference. Other elements are cloned and added.
- ref-to fires an event, 'deref-changed' and passes the element created in step 2 in the detail of the event. detail.createdElement.
- If the weak reference is dereferenced (discovered doing a get()), the ref-to element disappears.
- If the ref-to element is removed from the DOM, so is the element it created.
Alternative syntax:
<ref-to id=myRefTo></ref-to>
<script>
var newElement = document.createElement('my-element');
myRefTo.newRef = newElement;
</script>