Skip to content

Commit

Permalink
Add mutation state to store wait
Browse files Browse the repository at this point in the history
  • Loading branch information
bancek committed Dec 1, 2023
1 parent 0337f2e commit 869a04e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion vault-core-tests/src/helpers/repo_files_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub async fn details_wait<Filter: Fn(&RepoFilesDetails) -> bool + Send + Sync +
store::wait_for(
store.clone(),
&[store::Event::RepoFilesDetails],
move || {
move |_| {
store.with_state(|state| {
state
.repo_files_details
Expand Down
2 changes: 1 addition & 1 deletion vault-core-tests/src/helpers/transfers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ pub async fn transfer_wait<Filter: Fn(&Transfer) -> bool + Send + Sync + 'static
transfer_id: u32,
filter: Filter,
) {
store::wait_for(store.clone(), &[store::Event::Transfers], move || {
store::wait_for(store.clone(), &[store::Event::Transfers], move |_| {
store.with_state(|state| {
state
.transfers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ fn test_create_dir() {
let dialog_future = fixture.fake_remote.tokio_runtime.spawn(async move {
let wait_store = dialog_vault.store.clone();
let dialog_id =
store::wait_for(wait_store.clone(), &[store::Event::Dialogs], move || {
store::wait_for(wait_store.clone(), &[store::Event::Dialogs], move |_| {
wait_store.with_state(|state| {
dialogs::selectors::select_dialogs(state)
.iter()
Expand Down Expand Up @@ -472,7 +472,7 @@ fn test_create_dir_validation() {
let dialog_future = fixture.fake_remote.tokio_runtime.spawn(async move {
let wait_store = dialog_vault.store.clone();
let dialog_id =
store::wait_for(wait_store.clone(), &[store::Event::Dialogs], move || {
store::wait_for(wait_store.clone(), &[store::Event::Dialogs], move |_| {
wait_store.with_state(|state| {
dialogs::selectors::select_dialogs(state)
.iter()
Expand Down
4 changes: 2 additions & 2 deletions vault-core/src/repo_files_details/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl RepoFilesDetailsService {
store::wait_for(
self.store.clone(),
&[store::Event::RepoFilesDetails],
move || -> Option<Result<RepoFile, GetFilesReaderError>> {
move |_| -> Option<Result<RepoFile, GetFilesReaderError>> {
file_store.with_state(|state| selectors::select_file_reader_file(state, details_id))
},
)
Expand Down Expand Up @@ -545,7 +545,7 @@ impl RepoFilesDetailsService {
store::wait_for(
self.store.clone(),
&[store::Event::RepoFilesDetails],
move || {
move |_| {
saving_store.mutate(|state, notify, _, _| {
// wait for not saving
if selectors::select_is_saving(state, details_id) {
Expand Down
5 changes: 4 additions & 1 deletion vault-core/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ pub type Store = vault_store::Store<State, Event, MutationState, MutationEvent>;

pub type Subscription = vault_store::Subscription<State, Event, MutationState, MutationEvent>;

pub async fn wait_for<F: Fn() -> Option<R> + Send + Sync + 'static, R: Send + 'static>(
pub async fn wait_for<
F: Fn(Option<&MutationState>) -> Option<R> + Send + Sync + 'static,
R: Send + 'static,
>(
store: Arc<Store>,
events: &[Event],
f: F,
Expand Down
10 changes: 5 additions & 5 deletions vault-store/src/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ pub async fn wait_for<F, R, State, Event, MutationState, MutationEvent>(
f: F,
) -> R
where
F: Fn() -> Option<R> + Send + Sync + 'static,
F: Fn(Option<&MutationState>) -> Option<R> + Send + Sync + 'static,
R: Send + 'static,
State: Debug + Clone + Send + Sync + 'static,
Event: Debug + Clone + PartialEq + Eq + Hash + Send + 'static,
MutationState: Debug + Clone + Default + 'static,
MutationEvent: Debug + Clone + PartialEq + Eq + Hash + Send + 'static,
{
if let Some(res) = f() {
if let Some(res) = f(None) {
return res;
}

Expand All @@ -59,10 +59,10 @@ where
store.on(
subscription_id,
events,
Box::new(move |_, _| {
Box::new(move |mutation_state, _| {
let subscription_f = subscription_f.clone();

if let Some(res) = subscription_f() {
if let Some(res) = subscription_f(Some(mutation_state)) {
let sender = subscription_sender.lock().unwrap().take();

subscription_store.remove_listener(subscription_id);
Expand All @@ -75,7 +75,7 @@ where
);

// try again in case state changed between the first check and subscribe
if let Some(res) = f() {
if let Some(res) = f(None) {
store.remove_listener(subscription_id);

return res;
Expand Down

0 comments on commit 869a04e

Please sign in to comment.