MithrilJS / MithrilJS/mithril.js
I don't exactly trust `m.trust`... 😉
@dead-claudia is already working on this.
Since Nov 26, 2018.
- Dominant language
- JavaScript
- Stars
- 14.5k
- Forks
- 922
- PR merge metrics
- No merged PRs in 30d
Description
Expected Behavior
m.trust should be a bit more agnostic about its surrounding environment, and it shouldn't be so overly complicated.
Current Behavior
m.trust currently uses a really ugly series of hacks to render itself. It also only works with some HTML and SVG.
Possible Solution
Let's simplify it to something closer to this:
Edit: Simplify it further
var fragment = $doc.createDocumentFragment()
function createHTML(parent, vnode, nextSibling) {
// Not using the proper parent makes the child element(s) vanish.
// var div = document.createElement("div")
// div.innerHTML = "<td>i</td><td>j</td>"
// console.log(div.innerHTML)
// --> "ij", no <td> in sight.
//
// The below code does this generically regardless of namespace or tag name.
var temp = parent.firstChild == null ? parent : $doc.createElementNS(parent.nodeName, parent.namespaceURI)
temp.innerHTML = vnode.children
vnode.dom = temp.firstChild
vnode.domSize = temp.childNodes.length
if (temp !== parent) {
var child
while (child = temp.firstChild) fragment.appendChild(child)
insertNode(parent, fragment, nextSibling)
}
}
This is significantly smaller (like about 100 bytes saved), but I need to benchmark the rendering improvement though (it's not tested there currently). It does implement the optimization of if no other children exist, it can just render directly to the node and avoid the indirection.
Steps to Reproduce (for bugs)
Context
Just noticed it was weird, and that we were mostly just doing the wrong thing here.
Your Environment
- Version used:
- Browser Name and version:
- Operating System and version (desktop or mobile):
- Link to your project:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.