Synphonyte / leptos-use

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

`use_event_source` cannot retrieve error due to `StringCodec::Error` not implementing `Clone` #109

Closed littlebenlittle closed 4 months ago

littlebenlittle commented 5 months ago

Simple example:

let UseEventSourceReturn {
        ready_state,
        data,
        error,
        ..
} = use_event_source::<Media, JsonCodec>(
    format!("{}/api/media_library/events", client::get_origin()).as_str(),
);

create_effect(move |_| {
    log!(ready_state.get());
    log!("{:?}", data.get());
    log!("{:?}", error.get()); // Signal<Option<UseEventSourceError<JsonCodecError>>> does not implement Clone
});

The hack I came up to fix this (deriving Clone for UseEventSourceError and following the type errors) leads to some undesirable results for FromToStringCodec, because FromStr::Error has no trait bounds and hence no information can be extracted into a Clone-able error type. JsonCodec requires a little work (essentially just copying data from its methods into a new error type) to provide a Clone-able error, but this is not unreasonable.