Merge pull request #203 from DioxusLabs/jk/local-router
Feat: abstract the router on a per-platform basis and add docs
This commit is contained in:
33 files changed
+854
-552
No files matched your search
@@ -6,7 +6,7 @@ use std::{
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
type ProvidedState<T> = RefCell<ProvidedStateInner<T>>;
|
||||
type ProvidedState<T> = Rc<RefCell<ProvidedStateInner<T>>>;
|
||||
|
||||
// Tracks all the subscribers to a shared State
|
||||
pub struct ProvidedStateInner<T> {
|
||||
@@ -91,7 +91,7 @@ pub fn use_context<'a, T: 'static>(cx: &'a ScopeState) -> Option<UseSharedState<
|
||||
}
|
||||
|
||||
struct SharedStateInner<T: 'static> {
|
||||
root: Option<Rc<ProvidedState<T>>>,
|
||||
root: Option<ProvidedState<T>>,
|
||||
value: Option<Rc<RefCell<T>>>,
|
||||
scope_id: ScopeId,
|
||||
needs_notification: Cell<bool>,
|
||||
@@ -174,11 +174,11 @@ where
|
||||
///
|
||||
pub fn use_context_provider<T: 'static>(cx: &ScopeState, f: impl FnOnce() -> T) {
|
||||
cx.use_hook(|_| {
|
||||
let state: ProvidedState<T> = RefCell::new(ProvidedStateInner {
|
||||
let state: ProvidedState<T> = Rc::new(RefCell::new(ProvidedStateInner {
|
||||
value: Rc::new(RefCell::new(f())),
|
||||
notify_any: cx.schedule_update_any(),
|
||||
consumers: HashSet::new(),
|
||||
});
|
||||
}));
|
||||
cx.provide_context(state)
|
||||
});
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
use dioxus_core::{ScopeState, TaskId};
|
||||
pub use futures_channel::mpsc::{UnboundedReceiver, UnboundedSender};
|
||||
use std::future::Future;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// Maintain a handle over a future that can be paused, resumed, and canceled.
|
||||
///
|
||||
@@ -76,7 +75,7 @@ where
|
||||
/// Get a handle to a coroutine higher in the tree
|
||||
///
|
||||
/// See the docs for [`use_coroutine`] for more details.
|
||||
pub fn use_coroutine_handle<M: 'static>(cx: &ScopeState) -> Option<&Rc<CoroutineHandle<M>>> {
|
||||
pub fn use_coroutine_handle<M: 'static>(cx: &ScopeState) -> Option<&CoroutineHandle<M>> {
|
||||
cx.use_hook(|_| cx.consume_context::<CoroutineHandle<M>>())
|
||||
.as_ref()
|
||||
}
|
||||
@@ -86,6 +85,15 @@ pub struct CoroutineHandle<T> {
|
||||
task: TaskId,
|
||||
}
|
||||
|
||||
impl<T> Clone for CoroutineHandle<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
tx: self.tx.clone(),
|
||||
task: self.task,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> CoroutineHandle<T> {
|
||||
/// Get the ID of this coroutine
|
||||
#[must_use]
|
||||
|
||||
Reference in new issue
Block a user