intendednull / yewdux

Ergonomic state management for Yew applications
https://intendednull.github.io/yewdux/
Apache License 2.0
319 stars 31 forks source link

yew version conflict? #8

Closed johansmitsnl closed 3 years ago

johansmitsnl commented 3 years ago

I'm refactoring my yew app which is in a small state.

I have upgraded from yew = "0.17" -> yew = "0.18" (YEW) and yew-state = "0.4" -> yewdux = "0.6.1".

My relevant depends are:

yew = "0.18.0"
yew-router = "0.15.0"
yewdux = "0.6.1"
yewtil = "0.4"

I have used the example as my guideline but I'm getting this error:

error[E0308]: mismatched types
  --> frontend/src/components/account.rs:56:46
   |
56 |             dispatch: Dispatch::bridge_state(link.callback(Msg::State)),
   |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `yew::callback::Callback`, found enum `yew::Callback`
   |
   = note: expected enum `yew::callback::Callback<Rc<_>>`
              found enum `yew::Callback<Rc<AppState>>`
   = note: perhaps two different versions of crate `yew` are being used?

error[E0282]: type annotations needed
  --> frontend/src/views/home/index.rs:49:22
   |
49 |                     .reduce_callback(|app_state| app_state.jwt = None);
   |                      ^^^^^^^^^^^^^^^ cannot infer type for type parameter `E` declared on the associated function `reduce_callback`
   |
help: consider specifying the type arguments in the method call
   |
49 |                     .reduce_callback::<E, impl Fn(&mut Model<Self::Store>) + 'static>(|app_state| app_state.jwt = None);
   |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// account.rs
impl Component for Account {
    type Message = Msg;
    type Properties = Props;

    fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self {
        link.send_message(Msg::Initialize);

        Self {
            props,
            dispatch: Dispatch::bridge_state(link.callback(Msg::State)),
            state: Default::default(),
        }
    }
// index.rs
    fn update(&mut self, msg: Self::Message) -> ShouldRender {
        match msg {
            Msg::Logout => {
                self.storage_local.remove("jwt");

                self.dispatch
                    .reduce_callback(|app_state| app_state.jwt = None);

                let mut router =
                    RouteAgentBridge::new(self.link.callback(Self::Message::Navigation));
                router.send(RouteRequest::ReplaceRoute(AppRoute::Login.into()));

                false
            }

            Msg::Navigation(_) => {
                log::info!("Update Msg::Navigation in index");
                true
            }

            Msg::State(state) => {
                self.state = state;
                true
            }
        }
    }

What is wrong with the code or is yewdux not yew 0.17 or 0.18 ready?

deftsp commented 3 years ago

I suffered from this problem too. And fix it by specifying the yew* dependencies of your project and yewdux have the same version.

johansmitsnl commented 3 years ago

@deftsp could you share you Cargo.toml snippet to see how you did this?

deftsp commented 3 years ago

The yew project

  [dependencies]
  log = "0.4.14"
  yew = { git = "https://github.com/yewstack/yew", rev = "246bc59" }
  yew-functional = { git = "https://github.com/yewstack/yew", rev = "246bc59" }
  yew-router = { git = "https://github.com/yewstack/yew", rev = "246bc59" }
  yew-services = { git = "https://github.com/yewstack/yew", rev = "246bc59" }
  yewtil = { git = "https://github.com/yewstack/yew", rev = "246bc59"}
  yewdux = { git = "https://github.com/deftsp/yewdux", rev = "dbda686"}

The yewdux fork of the following change file: ./yewdux/yewdux/Cargo.toml

  [dependencies]
  serde = { version = "1.0.114", features = ["rc"] }
  yew = { git = "https://github.com/yewstack/yew", rev = "246bc59" }
  yew-services = { git = "https://github.com/yewstack/yew", rev = "246bc59" }
  yewtil = { git = "https://github.com/yewstack/yew", rev = "246bc59", optional = true }

Remember to execute "cargo update" to update the git rev

johansmitsnl commented 3 years ago

@deftsp I believe it works but pinning to specific version is not a long term solution. It looks like yewdux release is not correct.

intendednull commented 3 years ago

Dependencies are up to date now!