-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Diff does not capture on{event}
handlers
#132
Comments
You are welcome to provide a patch to offer such an option, but its not something I would have expected to be captured by a dom diffing library. So I'll close this for now but if you are willing to provide a patch, I'm willing to reopen this. If you do provide a patch, it should be done in such a way that it is not being done by default. |
Hi @johanneswilm! Thanks for the prompt reply. If you can provide guidance and feedback, I'm definitely willing to submit a PR for this! |
@cowboyd Writing this code would be a challenge. There are a number of questions one would need an answer for several questions such as:
I don't have a good answer myself. These are some of the reasons why I always attached event listeners at elements outside the dom element that was being diffed rather than inside. The specific element that the event started on could then be found by looking at |
@johanneswilm I agree, there are definitely some challenges here, and I think scoping the capability to a limited context is the only option. In my particular case, I'm only interested in transformations that happen in a single browsing context. Given that as a precursor:
Since callbacks added via
I don't think that would be possible, but again, would be out of scope. The DOM contains objects that simply cannot be serialized into HTML which is the key difference between DOM properties and attributes. In fact, unless a DOM property is explicitly bound to an HTML attribute, they will exist in completely different spaces; the attribute living in that which can be serialized into HTML and sent across the wire, and the property living purely within the realm of transient client state. let button = document.createElement("button")
button.hello = "World";
button.setAttribute("hello", "Planet");
button.hello //=> "World"
button.outerHTML //=> <button hello="Planet"></button>
I would imagine that a feature like this would require the addition of an operation such as In other words, because there is no expectation that DOM properties can be serialized into HTML, there would be no expectation that diffs of DOM properties would be applicable outside the context that generated them. Given these constraints, do you think I'm on the right track with a separate |
@cowboyd I'm a bit confused. If you are not actually diffing these and you just manually have to create |
Yes, without an example, it is all very abstract. So some context: I'm writing an interactive UI library using the Structured Concurrency library Effection and rather than have stateful html components that manage side effects, I'm toying with the idea of having the effects manage stateless html. Here is an actual example of a counter component, which is an inversion of the normal style. The effects "own" the html, not the other way around which is what we're used to. import { action, type Operation } from "effection"
export default function* Counter(): Operation<void> {
let count = 0;
while (true) {
yield* action(function*(resolve) {
yield* <button onclick={resolve}>Clicks: {count}</button>;
})
count++;
}
} As you can see, I'm using the When the In short, I'd like to be able to pass a continuation to a running effect directly as an event handler. I actually have a version of this code working without |
If the target DOM node contains event handler properties, they are not captured in the diff and therefore not subsequently applied.
https://codepen.io/cowboyd/pen/ExrEpwe?editors=1011
The text was updated successfully, but these errors were encountered: