Synphonyte / leptos-use

Collection of essential Leptos utilities inspired by React-Use / VueUse / SolidJS-USE
https://leptos-use.rs/
Apache License 2.0
309 stars 66 forks source link

`LocalStorage` integration #143

Closed CorvusPrudens closed 1 month ago

CorvusPrudens commented 1 month ago

Here's another significant PR. Hopefully we can avoid any such sweeping changes going forward.

This PR integrates the new Storage concept for signals. Anything that was trivially wrapped in a SendWrapper has now been converted to make use of LocalStorage.

This now compiles with my leptos branch that includes custom events, which has a PR waiting on approval leptos-rs/leptos#2762. This should now work with Leptos's main branch and the upcoming beta2 release.

I also swapped the type order for ElementMaybeSignal::Static from Option<SendWrapper<T>> to SendWrapper<Option<T>>, removing the need for cloning in a few places. I did something similar for ElementMaybeSignals as well.

There are probably several places where the bounds on types are overly strict. For example, watch_with_options does not have a local implementation. If there's a good approach for this in general, it might be nice to look into. I imagine people will often want to use many of these utilities with !Send types.

The two things that have not yet been ported are:

  1. From<HtmlElement<El>> for ElementMaybeSignal and similar
  2. use_active_element

Both of these rely on the old, eager Leptos element architecture to varying degrees. They'll need some assessment and will require more effort to port than the rest of the code.

I didn't notice there was more work on the upstream since my last commits. Hopefully my merge didn't step on anyone's toes!

maccesch commented 1 month ago

This is awesome, thank you so much!

Regarding local versions I have no good idea right now. That's something we're going to have to figure out over time I think.