viperHTML | Isomorphic hyperHTML
kandi X-RAY | viperHTML Summary
kandi X-RAY | viperHTML Summary
Isomorphic hyperHTML
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of viperHTML
viperHTML Key Features
viperHTML Examples and Code Snippets
Community Discussions
Trending Discussions on viperHTML
QUESTION
I'm trying to understand HyperHTML and how to get the best performance out of it.
Reading about how it works under the hood, it seems to imply that strong connections are made between a template and the DOM, which I take to mean that it requires a different mindset from VirtualDOM to optimise performance.
I wrote some code to show sorting of N elements in a table using hyperHtml vs normalHtml. The normalHtml version just flushes the table and rebuilds the elements. They both seem similar performance-wise. Am I comparing apples with oranges here? How can I make the hyperHtml version of the code perform better?
Code:
...ANSWER
Answered 2018-Sep-13 at 11:19Update
hyperHTML 2.14 introduced the usage of domdiff V2 which brings in petit-dom like performance with the cost of an extra 0.6K to the library, hopefully worth the change.
The original demo also had huge problems on Safari for some weird reason, most likely related to the fact nodes are appended directly as TR to the TABLE, instead of into the table TBODY element.
Anyway, you can now compare performance of the wired demo through this CodePen.
Please note everything said about the old snabdom diffing also is not relevant anymore.
It seems like you could have read a bit further than that, reaching the wire part, since you got the bind
one.
Basically, if you use an Array of strings as interpolated value, you are doing nothing different than an innerHTML
like operation, with all the regular side effects:
- every time you trash all nodes and create them from the scratch
- every reference to any node will be lost forever
- the amount of GC operations is higher
- the layout is XSS prone, hence not safe
To avoid replicating all these innerHTML
gotchas and use hyperHTML
properly, you need to wire
items to the node these represent.
QUESTION
I'm working on a Symfony application and just got SSR for JS working using https://github.com/spatie/server-side-rendering. So far I only worked with "readymade" SSR solutions for React, but currently I'm trying to use hyperHTML/viperHTML and am facing a few issues that so far I wasn't able to solve by looking at the available docs/examples.
My current test snippet is this:
...ANSWER
Answered 2018-Sep-10 at 05:11In case it helps, you can read viperHTML tests to see how components can be used.
The thing here is that without explicitly calling render() I get no output.
Components are meant to be used to render layout, either on the server or on the client side. This means if you pass a component instance to a hyper/viperHTML view, you don't have to worry about calling anything, it's done for you.
QUESTION
When I inspect the html elements created by the following code (using hyperHTML in Chrome, the entire list refreshes (I am assuming this based on all elements in the
- flashing purple briefly).
...
ANSWER
Answered 2018-Aug-24 at 23:04Sorry for the delay (I was on vacation) but the answer is simple: if you provide, as interpolation, an array of strings, you have the equivalent of an unsafe, and always new, innerHTML
operation, which is both possible but not suggested.
What you need to do, when you have real world data and items, usually as objects, is to relate each item with the piece of DOM it represent.
This is done with wire(...)
which accepts a reference, as object, and optionally an id.
Since the reference must be weak, for memory reasons, to recreate your demo you can relate all items to a single source as list
could be, and use each item value as unique id.
QUESTION
I have the following two components:
...ANSWER
Answered 2018-Apr-05 at 06:34update there is now a workaround provided by the hypermorphic module.
The ideal case scenario is that you have as dependency only viperhtml
, which in turns brings in hyperhtml
automatically, as you can see by the index.js file.
At that point, the client bundler should, if capable, tree shake unused code for you but you have a very good point that's not immediately clear.
I am also not fully sure if bundlers can be that smart, assuming that a check like typeof document === "object"
would always be true and target browsers only.
One way to try that, is to
QUESTION
I am starting to use hyperHTML have a question
starting with
...ANSWER
Answered 2017-Dec-17 at 15:36The main problem in your question is the example itself: a list of primitives, in this case numbers, used as generic element content.
This is not a so common real-world use case, where numbers comes from data and data is weakly referenciable.
However, if it's exactly a list of few numbers that you want inject as LI
elements, hyperHTML lets you do that, and if that's all you need, just go for it.
Now let me try to explain your question:
Why is wire better?
hyperHTML gives you a way to define various kind of content, including:
- text, which is automatically sanitized for you
- attributes, including events
- partial portions of the element that could be resolved lazily
You might want/need to use hyperHTML features to create elements as one-off operation.
A form, an input, a button, an image, if you want to quickly create a DOM element, you can do that via hyperHTML because it doesn't lock you in, it's rather an opt-in abstraction/library.
That is why you could relate a specific data object to a wire, but you could also simply use wires without references: it's OK for quick prototyping or small amount of changes.
Now let me show you few examples from that (reduced) list of features.
Point 1: text
If instead of plain numbers you have a list of book titles, what will your unwired code produce?
QUESTION
When using HyperHTMLElement
it's possible to access the contents of the component by simply using this.children
or this.querySelector()
, since it's an element.
But how would I achieve similar behavior when using hyper.Component
?
The hypothetical example I have in mind is from React docs: https://facebook.github.io/react/docs/refs-and-the-dom.html - I'd like to focus a specific node inside my DOM.
I have a codepen sandbox where I'm trying to solve this: https://codepen.io/asapach/pen/oGvdBd?editors=0010
The idea is that render()
returns the same Node
every time, so I could save it before returning and access it later as this.node
:
ANSWER
Answered 2017-Sep-12 at 00:55This is something I've worked on in the past via https://github.com/joshgillies/hypercomponent
The implementation is actually quite trivial.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install viperHTML
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page