Comments (5)
The elementOpen
function is expected to create an Element
, and be inserted as an Element
into the parent at the current location. As a result, a DocumentFragment
won't work in its place. You can create a nested patch if you need to work with a DocumentFragment
however. For example:
function render() {
elementOpen('div');
renderFragment();
elementClose('div');
}
function renderFragment() {
const frag = patch(document.createDocumentFragment(), () => {
text('Hello world');
});
// Do something with frag.
// Note: If you try to append the content to the current parent, the content
// will get removed by `elementClose`, unless you call `skip()`.
}
const el = document.createElement('div');
patch(el, render);
from incremental-dom.
Actually, that's also relevant for
<template>
case:function renderPart() { let el = elementOpen(tpl); text('Hello world'); elementClose(tpl); } function tpl () { return document.importNode(templateEl.content) } let templateEl = document.createElement('template') let el = document.createElement('div') patch(el, renderPart);That gives same error.
So raising back same questions:
- Would that be considered a valuable feature?
- Is there a workaround now for this?
I'm not sure I quite understand the goal of this particular example with respect to rendering "Hello World". Since a template's contents are a tree, it isn't clear to me where in the template's cloned content "Hello world" would be rendered.
If you do need to clone a template as a static subtree, you will want to make sure you also tell Incremental DOM to skip the contents so it does not remove it via a diff. For example:
function renderTemplate(template) {
// Incremental DOM currently requires you have an extra container for rendering
// content into.
const el = elementOpen('div', '<use a key to avoid conflicts>');
// If already rendered the template, skip this part and just reuse it.
if (!el._templateRendered) {
el.appendChild(document.importNode(template.content, true));
el._templateRendered = true;
}
// Tell Incremental DOM to ignore all the content of the element so it isn't
// removed.
skip();
elementClose('div');
}
from incremental-dom.
Actually, that's also relevant for <template>
case:
function renderPart() {
let el = elementOpen(tpl);
text('Hello world');
elementClose(tpl);
}
function tpl () {
return document.importNode(templateEl.content)
}
let templateEl = document.createElement('template')
let el = document.createElement('div')
patch(el, renderPart);
That gives same error.
So raising back same questions:
- Would that be considered a valuable feature?
- Is there a workaround now for this?
from incremental-dom.
we use idom
with DocumentFragments
regularly - am i missing something?
from incremental-dom.
Thank you for the solutions, patching internal fragment worked.
from incremental-dom.
Related Issues (20)
- Element Events list HOT 2
- Is Angular 8 Ivy render engine going to effectively replace this project? HOT 2
- Ignoring certain attributes HOT 6
- Update dependencies to remove security warnings
- Extended custom element creation HOT 5
- Issues with webpack and babel HOT 3
- Document: `elementVoid` is incorrect. HOT 2
- Setting prop using Boolean (to trigger prop over attribute) always sets true HOT 7
- Create function loses content HOT 2
- [Performance Advice] Patching to single element or custom elements HOT 16
- Runnable in jsdom (server side rendering)
- Add a module build HOT 2
- Twing implementation HOT 6
- Relationship to Lit / Polymer? HOT 5
- Do not publish ts sources to npm HOT 4
- CDN version not up to date. HOT 2
- Test not launching on macOS 11.2 / Chrome 89
- Details disclosure element <details> adds and removes "open" attribute outside of incrementalDOM HOT 2
- [Performance Advice] `key` parameter for `text()` function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from incremental-dom.