intendednull / yewdux

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

The Id of the handler, while present in the slab, is not associated with a callback #24

Closed lpotthast closed 2 years ago

lpotthast commented 2 years ago

Using yew = "0.19" yewdux = "0.7"

When having any store, for example (does not have to be persistent):

  use serde::{Serialize, Deserialize};
  use yewdux::prelude::*;

  pub type ThemeStore = PersistentStore<Theme>; 

  #[derive(Clone, PartialEq, Default, Serialize, Deserialize)]
  pub struct Theme {
      pub is_dark_mode: bool,
  }

  impl Persistent for Theme {
      fn area() -> Area {
          Area::Session // Default is Area::Local
      }
  }

And using the store in a component like:

fn create(ctx: &Context<Self>) -> Self {
    Self {
        ...
        theme_dispatch: Dispatch::bridge_state(ctx.link().callback(Msg::ThemeUpdated)),
        theme_state: Default::default(),
    }
}

fn update(&mut self, _ctx: &Context<Self>, msg: Self::Message) -> bool {
    match msg {
        Msg::ThemeUpdated(new_state) => {
            self.theme_state = new_state;
            true
        }
        Msg::ToggleDarkMode => {
            self.theme_dispatch
                .reduce(|theme| theme.is_dark_mode = !theme.is_dark_mode);
            false
        }
    }
}

on the call of self.theme_dispatch.reduce, the following warning is printed to the console:

The Id of the handler: 2, while present in the slab, is not associated with a callback.

This, as stated above, happens with ANY call to reduce. Creating the dispatcher with Dispatch::new() (if I don't want't to be notified about state-changes) does not make a difference. Did I miss anything or should I do something differently?

intendednull commented 2 years ago

You're not doing anything wrong, this is a known issue. You can safely ignore it for now. Fixed on master so it'll be gone by next release.

Related to https://github.com/yewstack/yew/issues/870

lpotthast commented 2 years ago

Thanks for the feedback! Saw that too. When living on the edge using

yew = { git = "https://github.com/yewstack/yew", features = ["csr"] }
yew-router = { git = "https://github.com/yewstack/yew.git" }
yewdux = { git = "https://github.com/intendednull/yewdux" }

and replacing all occurrences of bridge_state with subscribe and using the new store macro, everything works as expected. 👍