Call `on_change` on creation for listeners
Hello, I think listeners should receive on_change immediately on creation. It may not make a lot of sense at first, but when you look at DerivedFrom - it is created lazily, and is Default::default(), by default. This means that the store it is being derived from may already have state, but the derived store will not "derive" (call on_change) until that parent store changed in some way. It took me a while to debug the issue. I am currently using this:
impl Store for DerivedOne {
fn new(cx: &::yewdux::Context) -> Self {
let store: Rc<ParentOne> = cx.get();
cx.derived_from_mut::<ParentOne, Self>();
let mut this = Default::default();
<Self as DerivedFromMut<ParentOne>>::on_change(&mut this, store);
this
}
fn should_notify(&self, other: &Self) -> bool {
self != other
}
}
But I believe that this should be the default. And I think this applies even for listeners, which will also resolve the issue with derived state, thus not requiring this.
I think you are correct. Thanks for the feedback!
I am away from home for another week. Feel free to open a PR, otherwise I can when back :)