Giter VIP home page Giter VIP logo

Comments (7)

dbrgn avatar dbrgn commented on May 14, 2024 1

Yes, a regular reference will probably suffice. The good thing is that the compiler will tell us whether it's needed or not πŸ™‚

from percy.

chinedufn avatar chinedufn commented on May 14, 2024

Ahhh thanks for raising this.. I'd actually forgotten about this.

It's not mandatory, IIRC I had a lifetime issue and just did it this way to make it work. This was either before web_sys existed or shortly after it was published..

Regardless it's not desired.. so if you want to take a stab at making it mutable I'd be happy to answer any questions along the way!

from percy.

dbrgn avatar dbrgn commented on May 14, 2024

Will probably give this a try next week!

from percy.

chinedufn avatar chinedufn commented on May 14, 2024

Sweet! Again, I really don’t remember the problem, it might not have even been lifetimes and instead have been multiple mutable references or something.

Regardless I’m sure it was just poor form on my end and not a fundamental issue.

Although does this suggest that we might want a reference instead of a miracle reference ...?

rustwasm/wasm-bindgen#1061

from percy.

dbrgn avatar dbrgn commented on May 14, 2024

Hm, it's not that easy, because you are inserting the element into the nodes_to_patch hashmap.

This should be doable with only references by rewriting the patching algorithm. I'll try to take a quick look when I find time, but don't know yet if that'll be today or not.

from percy.

dbrgn avatar dbrgn commented on May 14, 2024

Ok, changing it to references using the same recursive algorithm is a bit tricky because of the lifetimes involved.

Since the Element is clonable we could simply clone it (see master...dbrgn:patch-ownership), but I'm not sure if that's worth the improved API because this way the element always gets cloned, while it might not need to be cloned if the user doesn't need the reference to the element anymore after patching.

Another option would be to accept the element by value, to create an Rc from it, and to pass that Rc to the find_nodes function. Then in the end we could return the original element by value. But every Rc causes an allocation and I'm not even sure how to unwrap the Rc to recover the original value πŸ™‚ So I think it might be best to stick to the current approach unless someone figures out lifetime annotations to be able to stick to references only.

TLDR: The user can clone the element before passing it to the patch function.

from percy.

chinedufn avatar chinedufn commented on May 14, 2024

SWEET thanks for looking into this!

Ah so it was a lifetime issue - I vaguely remember haha ..

Sweet this sounds great for now πŸ‘πŸΏ

from percy.

Related Issues (20)

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.