Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listener Injection #52

Merged
merged 4 commits into from
Mar 16, 2023

Conversation

wainwrightmark
Copy link
Contributor

Closes #51

This allows you to inject listeners into the #[store] macro

#[derive(Default, Clone, PartialEq, Eq, Deserialize, Serialize, Store)]
#[store(storage = "local", listener(LogListener))]
struct State {
    count: u32,
}

struct LogListener;
impl Listener for LogListener {
    type Store = State;

    fn on_change(&mut self, state: Rc<Self::Store>) {
        log!(Level::Info, "Count changed to {}", state.count);
    }
}

This also fixes a bug where adding more than one listener would drop previous listeners.

Copy link
Owner

@intendednull intendednull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@intendednull intendednull merged commit b046f6b into intendednull:master Mar 16, 2023
@intendednull
Copy link
Owner

Thank you for your contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Have a way to inject listeners into derived Store implementation
2 participants