-
Notifications
You must be signed in to change notification settings - Fork 178
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
Statics Diffing #152
Statics Diffing #152
Conversation
2bac69f
to
b40e4a3
Compare
b40e4a3
to
9192db4
Compare
9192db4
to
a86e8fc
Compare
Note that this'll create an unfortunate slow down for pre-rendered nodes that where previous sibling has a key. <ul id="container">
<li key="1" class="list">...</li>
<li key="2" class="list">...</li>
<li key="3" class="list">...</li>
...
</ul> var listStatics = ['class', 'list'];
patch(container, (list) => {
list.each((item, i) => {
elementVoid('li', i, list);
});
}, list); That's because With something like #127, this can be easily worked around. |
After some thinking about it, this is really not the right thing to do. If statics change, it is a pretty strong signal that something has appeared or disappeared. Take the following example:
If condition goes from 'false' to Instead, the right thing is to check if
We would also need have a way of importing what the statics are from a server-side render to make sure it is always correct if the first diff is done with different data. This could be done with a special attribute that lists out what the static attributes for the current node are. We also need to import the attributes when encountering a DOM node that doesn't have a I'll work on this change when I get a chance. |
I'd be ok with that. But note that this will immensely impact anyone using inline statics, including any build step that's not advanced enough to hoist.
If this is to highlight the case I brought up, I think not eagerly creating the |
Yeah, I'm still re-thinking that part. I'll probably just check that the element has all the attributes with the same value as listed in statics. It isn't 100% correct, but hopefully shouldn't really be an issue. You could always use a marker attribute, something like
The whole importing an existing DOM tree definitely needs a bit more thought. If there is a clean way, having a cache-free implementation might be nice too. |
Resolves #150.
Looking at this last night, I actually think this is the worst approach. Consider:
On their own, both
div
s pass "statics have the same reference". But used together, they're a time bomb waiting for production.This can be gotten around by requiring a key to use statics, but I don't think that's a scalable solution for templating libraries. And requiring a dev to provide a key just to write something as simple as
<a href="/foo" />
is a nonstarter.Instead, I think treating statics as special dynamics is the best approach. Since we're provided an array reference, just check strict equality of the array. If it matches, we're done. If not, perform the same attribute-change algorithm we use for dynamics.