Skip to content

Commit d0a405a

Browse files
committed
2 parents c4ad549 + 372f53e commit d0a405a

File tree

4 files changed

+59
-40
lines changed

4 files changed

+59
-40
lines changed

Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "dioxus-query"
33
description = "Fully-typed, async, reusable cached state management for Dioxus 🧬"
4-
version = "0.8.0"
4+
version = "0.9.0"
55
edition = "2021"
66
license = "MIT"
77
authors = ["Marc Espín <[email protected]>"]
@@ -12,11 +12,16 @@ keywords = ["dioxus", "async", "state", "synchronization"]
1212
categories = ["gui", "asynchronous"]
1313

1414
[dependencies]
15-
dioxus-lib = { version = "0.6", default-features = false, features = ["macro", "hooks", "signals"] }
15+
dioxus = { version = "0.7.0", default-features = false, features = ["macro", "hooks", "signals"] }
16+
dioxus-core = { version = "0.7.0", default-features = false }
1617
futures-util = "0.3.28"
17-
warnings = "0.2.1"
1818
tokio = { version = "^1", features = ["sync", "time"] }
1919

20+
[target.'cfg(target_arch = "wasm32")'.dependencies]
21+
wasmtimer = "0.4.1"
22+
web-time = "1.1.0"
23+
tokio = { version = "^1", features = ["sync"] }
24+
2025
[dev-dependencies]
21-
dioxus = { version = "0.6", features = ["desktop"] }
26+
dioxus = { version = "0.7.0", features = ["desktop"] }
2227
tokio = { version = "^1", features = ["time"] }

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ See the [Docs](https://docs.rs/dioxus-query/latest/dioxus_query/) or join the [D
88

99
## Support
1010

11-
- **Dioxus v0.6** 🧬
12-
- All renderers ([web](https://dioxuslabs.com/learn/0.4/getting_started/wasm), [desktop](https://dioxuslabs.com/learn/0.4/getting_started/desktop), [freya](https://github.com/marc2332/freya), etc)
13-
- Both WASM and native targets
11+
- **Dioxus v0.7** 🧬
12+
- Web, Desktop, and Blitz support
1413

1514
## Features
1615
- [x] **Renderer-agnostic**

src/mutation.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
use core::fmt;
2+
use dioxus::prelude::*;
3+
use dioxus::{
4+
hooks::{use_memo, use_reactive},
5+
signals::CopyValue,
6+
};
7+
use dioxus_core::{provide_root_context, spawn_forever, use_drop, ReactiveContext, Task};
28
use std::{
39
cell::{Ref, RefCell},
410
collections::{HashMap, HashSet},
@@ -9,14 +15,14 @@ use std::{
915
sync::{Arc, Mutex},
1016
time::Duration,
1117
};
12-
13-
use dioxus_lib::prelude::*;
14-
use dioxus_lib::signals::{Readable, Writable};
15-
use dioxus_lib::{
16-
hooks::{use_memo, use_reactive},
17-
signals::CopyValue,
18-
};
18+
#[cfg(not(target_family = "wasm"))]
19+
use tokio::time;
20+
#[cfg(not(target_family = "wasm"))]
1921
use tokio::time::Instant;
22+
#[cfg(target_family = "wasm")]
23+
use wasmtimer::tokio as time;
24+
#[cfg(target_family = "wasm")]
25+
use web_time::Instant;
2026

2127
pub trait MutationCapability
2228
where
@@ -180,14 +186,14 @@ impl<Q: MutationCapability> MutationsStorage<Q> {
180186

181187
// Spawn clean up task if there no more reactive contexts
182188
if mutation_data.reactive_contexts.lock().unwrap().is_empty() {
183-
*mutation_data.clean_task.borrow_mut() = spawn_forever(async move {
189+
*mutation_data.clean_task.borrow_mut() = Some(spawn_forever(async move {
184190
// Wait as long as the stale time is configured
185-
tokio::time::sleep(mutation.clean_time).await;
191+
time::sleep(mutation.clean_time).await;
186192

187193
// Finally clear the mutation
188194
let mut storage = storage_clone.write();
189195
storage.remove(&mutation);
190-
});
196+
}));
191197
}
192198
}
193199

src/query.rs

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,24 @@ use std::{
1010
time::Duration,
1111
};
1212

13-
use ::warnings::Warning;
14-
use dioxus_lib::prelude::Task;
15-
use dioxus_lib::prelude::*;
16-
use dioxus_lib::signals::{Readable, Writable};
17-
use dioxus_lib::{
13+
use dioxus::prelude::*;
14+
use dioxus::{
1815
hooks::{use_memo, use_reactive},
1916
signals::CopyValue,
2017
};
18+
use dioxus_core::{
19+
provide_root_context, spawn_forever, use_drop, ReactiveContext, SuspendedFuture, Task,
20+
};
2121
use futures_util::stream::{FuturesUnordered, StreamExt};
22-
use tokio::{sync::Notify, time::Instant};
22+
use tokio::sync::Notify;
23+
#[cfg(not(target_family = "wasm"))]
24+
use tokio::time;
25+
#[cfg(not(target_family = "wasm"))]
26+
use tokio::time::Instant;
27+
#[cfg(target_family = "wasm")]
28+
use wasmtimer::tokio as time;
29+
#[cfg(target_family = "wasm")]
30+
use web_time::Instant;
2331

2432
pub trait QueryCapability
2533
where
@@ -222,13 +230,12 @@ impl<Q: QueryCapability> QueriesStorage<Q> {
222230
let task = spawn_forever(async move {
223231
loop {
224232
// Wait as long as the stale time is configured
225-
tokio::time::sleep(interval).await;
233+
time::sleep(interval).await;
226234

227235
// Run the query
228236
QueriesStorage::<Q>::run_queries(&[(&query_clone, &query_data_clone)]).await;
229237
}
230-
})
231-
.expect("Failed to spawn interval task.");
238+
});
232239
*interval_task = Some((interval, task));
233240
}
234241

@@ -248,14 +255,14 @@ impl<Q: QueryCapability> QueriesStorage<Q> {
248255

249256
// Spawn clean up task if there no more reactive contexts
250257
if query_data.reactive_contexts.lock().unwrap().is_empty() {
251-
*query_data.clean_task.borrow_mut() = spawn_forever(async move {
258+
*query_data.clean_task.borrow_mut() = Some(spawn_forever(async move {
252259
// Wait as long as the stale time is configured
253-
tokio::time::sleep(query.clean_time).await;
260+
time::sleep(query.clean_time).await;
254261

255262
// Finally clear the query
256263
let mut storage = storage_clone.write();
257264
storage.remove(&query);
258-
});
265+
}));
259266
}
260267
}
261268

@@ -301,23 +308,23 @@ impl<Q: QueryCapability> QueriesStorage<Q> {
301308
for reactive_context in query_data.reactive_contexts.lock().unwrap().iter() {
302309
reactive_context.mark_dirty();
303310
}
304-
}
305311

306-
// Notify the suspense task if any
307-
if let Some(suspense_task) = &*query_data.suspense_task.borrow() {
308-
suspense_task.notifier.notify_waiters();
309-
};
312+
// Notify the suspense task if any
313+
if let Some(suspense_task) = &*query_data.suspense_task.borrow() {
314+
suspense_task.notifier.notify_waiters();
315+
};
316+
}
310317

311318
// Spawn clean up task if there no more reactive contexts
312319
if query_data.reactive_contexts.lock().unwrap().is_empty() {
313-
*query_data.clean_task.borrow_mut() = spawn_forever(async move {
320+
*query_data.clean_task.borrow_mut() = Some(spawn_forever(async move {
314321
// Wait as long as the stale time is configured
315-
tokio::time::sleep(query.clean_time).await;
322+
time::sleep(query.clean_time).await;
316323

317324
// Finally clear the query
318325
let mut storage = storage.storage.write();
319326
storage.remove(&query);
320-
});
327+
}));
321328
}
322329

323330
QueryReader {
@@ -387,6 +394,11 @@ impl<Q: QueryCapability> QueriesStorage<Q> {
387394
for reactive_context in query_data.reactive_contexts.lock().unwrap().iter() {
388395
reactive_context.mark_dirty();
389396
}
397+
398+
// Notify the suspense task if any
399+
if let Some(suspense_task) = &*query_data.suspense_task.borrow() {
400+
suspense_task.notifier.notify_waiters();
401+
};
390402
}));
391403
}
392404

@@ -597,9 +609,6 @@ impl<Q: QueryCapability> UseQuery<Q> {
597609
Q::Ok: Clone,
598610
Q::Err: Clone,
599611
{
600-
let _allow_write_in_component_body =
601-
::warnings::Allow::new(warnings::signal_write_in_component_body::ID);
602-
603612
let storage = consume_context::<QueriesStorage<Q>>();
604613
let mut storage = storage.storage.write_unchecked();
605614
let query_data = storage.get_mut(&self.query.peek()).unwrap();

0 commit comments

Comments
 (0)