Giter VIP home page Giter VIP logo

udomdiff's Issues

Compare Function

Hi, I really like domdiff and found out about udomdiff recently.
I also saw that udomdiff is more performant and smaller but does not provide a compare function, like domdiff does.

So I replaced lines https://github.com/WebReflection/udomdiff/blob/master/index.js#L59,
https://github.com/WebReflection/udomdiff/blob/master/index.js#L63 and https://github.com/WebReflection/udomdiff/blob/master/index.js#L69 with the compare Function and run into Problems with insertBefore on line 49.

How would it be possible to add it again?

Can the algorithm be generalised?

@WebReflection I'm not even sure if this package is the current?, you have a million of packages xD

anyway, the question is: can the algorithm be generalized? This is also useful for merging stores, albeit I am not really that sure about that. Solid seems to use some versions, or modifications of this algo, in different situations and I am wondering if can be generalized, because I am currently dealing with the same thing, I need to patch the dom, and I also need to patch stores.
https://github.com/solidjs/solid/blob/dbdc27df2246ec05c0e32cf7b461ddbe4223915f/packages/solid/store/src/modifiers.ts#L3

maybe not all diffing, because this
https://github.com/solidjs/solid/blob/dbdc27df2246ec05c0e32cf7b461ddbe4223915f/packages/solid/src/reactive/array.ts
seems to come from
https://github.com/adamhaile/S-array

https://github.com/ryansolid/dom-expressions/blob/main/packages/dom-expressions/src/reconcile.js

Do you see any approach to generalise this problem?

Thanks!

Add benchmarks

Would be possible to add some benchmarks to the repo if you have the code ? I have tried udomdiff a couple of times but surprisingly it's slightly slower. Which is highly suspicious or what I am doing is just faster in some situations. Even if I don't use I would love to give ideas to improve its speed when in scope of what you expect from this lib.

With some benchmark added I could test implementations and show off situations that you may consider improving. For example if diffing is only about removals this may be faster(or maybe not) but you will get an idea of what I am thinking

export function remove(prev = [], node = []) {
	for (let i = 0, item; i < prev.length; i++) {
		item = prev[i]
		item &&
			(node.length === 0 || !node.includes(item)) &&
			item.remove()
	}
	return node
}

Unnecessary (?) extra move operation

Hey,

I've been testing out some diffing algos, curious to see which DOM operations they actually perform.

One of the libraries I tested was this one, and I've come across a case where it seems to do an unnecessary DOM operation.

Here's my test bench:

https://jsfiddle.net/mindplay/o4gbaqw0/

I've added console.log statements for every DOM operation - you can press the buttons to perform various array operations to change the sorting of the elements, and then watch the console output for the exact DOM operations resulting from the diff operation from one state to the next.

It looks good for all operations except "Rotate Up" - which basically means, "take the first item on the list and move it to the bottom", which should be doable with a single insertBefore.

Instead, the result is two operations - a seemingly unnecessary replaceChild operation, followed by the expected insertBefore operation. (The resulting DOM state is correct though.)

With devtools open, you can see two nodes are being affected:

image

It isn't explicitly stated in the README of either this project or the original domdiff, but presumably the point of diffing is to perform as few DOM operations as possible? Just figured I'd report my findings, in case you do consider this a subtle "bug". 🙂

implementing liveview by sending diff data as JSON

The function udomdiff applies changes directly. Is there a way that I can get the diff (serializable as JSON) and then later apply the diff?

pseudocode demostrating the concept:

diff = get_patch(newnode, oldnode)
apply_patch(oldnode, diff)

This will be useful when there are two copies of oldnode (DOM) on server and browser respectively.

Then, I can patch uhtml render(oldnode, html`...`) (run on server) to update the browser DOM. Event handlers is a bit tricky, and can theoretically be diffed as well.

Optimal way to handle fragments

This is really an awesome piece of code! Congrats!

I'm trying to incorporate it in sinuous/map.
I was wondering about a use case when an item is a document fragment.
I see it works nicely with arrays.

what do you recommend for handling fragments?
convert the list items to arrays first or use something like uwire?

thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.