Closed lpotthast closed 2 years ago
Fixed in 452faf1
Should work now. You can also get the current state directly if needed:
let dispatch = Dispatch::<State>::subscribe(ctx.link().callback(Msg::StateUpdated));
Self {
state: dispatch.get(),
dispatch,
}
Works perfectly with the change applied.
And thanks for noting the .get function. But Rust yells here when trying to call .get()
, as
no method named `get` found for struct `yewdux::dispatch::Dispatch<State>` [...]
the candidate is defined in an impl for the type `yewdux::dispatch::Dispatch<S>[...]
use associated function syntax instead: `yewdux::dispatch::Dispatch::<State>::get`
Using Dispatch::<State>::get()
works, but I think I will just stick to using Default::default(), as the state is cloned/replaced either way..
@inf0rm4tik3r oops! get
should be fixed now. There was a couple others like that, plus a bug with Mrc that is fixed too.
When using the new
Store
macro as in https://github.com/intendednull/yewdux/tree/master/examples/persistent, that is, using a function component, everything works as expected.But when using the persistent store in a struct component with:
When the component is created with an old state persisted in the browser, that state is not passed to the component with a Msg::StateUpdated message. The
state
field inside the component struct will just stay to whatDefault::default()
returned. Only a state change happening after the component was created will pass the current state to the component using the message.