feat: change schedule_update's Rc to an Arc
BREAKING CHANGE
This commit is contained in:
7 files changed
+19
-19
No files matched your search
@@ -10,7 +10,7 @@ use std::{
|
|||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
future::Future,
|
future::Future,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
rc::Rc,
|
rc::Rc, sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// for traceability, we use the raw fn pointer to identify the function
|
/// for traceability, we use the raw fn pointer to identify the function
|
||||||
@@ -582,9 +582,9 @@ impl ScopeState {
|
|||||||
/// Create a subscription that schedules a future render for the reference component
|
/// Create a subscription that schedules a future render for the reference component
|
||||||
///
|
///
|
||||||
/// ## Notice: you should prefer using prepare_update and get_scope_id
|
/// ## Notice: you should prefer using prepare_update and get_scope_id
|
||||||
pub fn schedule_update(&self) -> Rc<dyn Fn() + 'static> {
|
pub fn schedule_update(&self) -> Arc<dyn Fn() + 'static> {
|
||||||
let (chan, id) = (self.tasks.sender.clone(), self.scope_id());
|
let (chan, id) = (self.tasks.sender.clone(), self.scope_id());
|
||||||
Rc::new(move || {
|
Arc::new(move || {
|
||||||
let _ = chan.unbounded_send(SchedulerMsg::Immediate(id));
|
let _ = chan.unbounded_send(SchedulerMsg::Immediate(id));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -594,9 +594,9 @@ impl ScopeState {
|
|||||||
/// A component's ScopeId can be obtained from `use_hook` or the [`ScopeState::scope_id`] method.
|
/// A component's ScopeId can be obtained from `use_hook` or the [`ScopeState::scope_id`] method.
|
||||||
///
|
///
|
||||||
/// This method should be used when you want to schedule an update for a component
|
/// This method should be used when you want to schedule an update for a component
|
||||||
pub fn schedule_update_any(&self) -> Rc<dyn Fn(ScopeId)> {
|
pub fn schedule_update_any(&self) -> Arc<dyn Fn(ScopeId)> {
|
||||||
let chan = self.tasks.sender.clone();
|
let chan = self.tasks.sender.clone();
|
||||||
Rc::new(move |id| {
|
Arc::new(move |id| {
|
||||||
let _ = chan.unbounded_send(SchedulerMsg::Immediate(id));
|
let _ = chan.unbounded_send(SchedulerMsg::Immediate(id));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::{any::Any, cell::RefCell, collections::HashMap, rc::Rc};
|
use std::{any::Any, cell::RefCell, collections::HashMap, rc::Rc, sync::Arc};
|
||||||
|
|
||||||
use dioxus_core::ScopeId;
|
use dioxus_core::ScopeId;
|
||||||
use im_rc::HashSet;
|
use im_rc::HashSet;
|
||||||
@@ -9,7 +9,7 @@ pub type AtomId = *const ();
|
|||||||
|
|
||||||
pub struct AtomRoot {
|
pub struct AtomRoot {
|
||||||
pub atoms: RefCell<HashMap<AtomId, Slot>>,
|
pub atoms: RefCell<HashMap<AtomId, Slot>>,
|
||||||
pub update_any: Rc<dyn Fn(ScopeId)>,
|
pub update_any: Arc<dyn Fn(ScopeId)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Slot {
|
pub struct Slot {
|
||||||
@@ -18,7 +18,7 @@ pub struct Slot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AtomRoot {
|
impl AtomRoot {
|
||||||
pub fn new(update_any: Rc<dyn Fn(ScopeId)>) -> Self {
|
pub fn new(update_any: Arc<dyn Fn(ScopeId)>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
update_any,
|
update_any,
|
||||||
atoms: RefCell::new(HashMap::new()),
|
atoms: RefCell::new(HashMap::new()),
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use dioxus_core::{ScopeId, ScopeState};
|
|||||||
use std::{
|
use std::{
|
||||||
cell::{Cell, Ref, RefCell, RefMut},
|
cell::{Cell, Ref, RefCell, RefMut},
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
rc::Rc,
|
rc::Rc, sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
type ProvidedState<T> = RefCell<ProvidedStateInner<T>>;
|
type ProvidedState<T> = RefCell<ProvidedStateInner<T>>;
|
||||||
@@ -10,7 +10,7 @@ type ProvidedState<T> = RefCell<ProvidedStateInner<T>>;
|
|||||||
// Tracks all the subscribers to a shared State
|
// Tracks all the subscribers to a shared State
|
||||||
pub struct ProvidedStateInner<T> {
|
pub struct ProvidedStateInner<T> {
|
||||||
value: Rc<RefCell<T>>,
|
value: Rc<RefCell<T>>,
|
||||||
notify_any: Rc<dyn Fn(ScopeId)>,
|
notify_any: Arc<dyn Fn(ScopeId)>,
|
||||||
consumers: HashSet<ScopeId>,
|
consumers: HashSet<ScopeId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use dioxus_core::{ScopeState, TaskId};
|
use dioxus_core::{ScopeState, TaskId};
|
||||||
use std::{cell::Cell, future::Future, rc::Rc};
|
use std::{cell::Cell, future::Future, rc::Rc, sync::Arc};
|
||||||
|
|
||||||
pub fn use_future<'a, T: 'static, F: Future<Output = T> + 'static>(
|
pub fn use_future<'a, T: 'static, F: Future<Output = T> + 'static>(
|
||||||
cx: &'a ScopeState,
|
cx: &'a ScopeState,
|
||||||
@@ -43,7 +43,7 @@ pub fn use_future<'a, T: 'static, F: Future<Output = T> + 'static>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct UseFuture<T> {
|
pub struct UseFuture<T> {
|
||||||
update: Rc<dyn Fn()>,
|
update: Arc<dyn Fn()>,
|
||||||
needs_regen: Cell<bool>,
|
needs_regen: Cell<bool>,
|
||||||
value: Option<T>,
|
value: Option<T>,
|
||||||
slot: Rc<Cell<Option<T>>>,
|
slot: Rc<Cell<Option<T>>>,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use dioxus_core::ScopeState;
|
use dioxus_core::ScopeState;
|
||||||
use std::{
|
use std::{
|
||||||
cell::{Ref, RefCell, RefMut},
|
cell::{Ref, RefCell, RefMut},
|
||||||
rc::Rc,
|
rc::Rc, sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// `use_ref` is a key foundational hook for storing state in Dioxus.
|
/// `use_ref` is a key foundational hook for storing state in Dioxus.
|
||||||
@@ -121,7 +121,7 @@ pub fn use_ref<'a, T: 'static>(
|
|||||||
|
|
||||||
/// A type created by the [`use_ref`] hook. See its documentation for more details.
|
/// A type created by the [`use_ref`] hook. See its documentation for more details.
|
||||||
pub struct UseRef<T> {
|
pub struct UseRef<T> {
|
||||||
update: Rc<dyn Fn()>,
|
update: Arc<dyn Fn()>,
|
||||||
value: Rc<RefCell<T>>,
|
value: Rc<RefCell<T>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use dioxus_core::prelude::*;
|
|||||||
use std::{
|
use std::{
|
||||||
cell::{RefCell, RefMut},
|
cell::{RefCell, RefMut},
|
||||||
fmt::{Debug, Display},
|
fmt::{Debug, Display},
|
||||||
rc::Rc,
|
rc::Rc, sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Store state between component renders.
|
/// Store state between component renders.
|
||||||
@@ -69,7 +69,7 @@ pub fn use_state<'a, T: 'static>(
|
|||||||
|
|
||||||
pub struct UseState<T: 'static> {
|
pub struct UseState<T: 'static> {
|
||||||
pub(crate) current_val: Rc<T>,
|
pub(crate) current_val: Rc<T>,
|
||||||
pub(crate) update_callback: Rc<dyn Fn()>,
|
pub(crate) update_callback: Arc<dyn Fn()>,
|
||||||
pub(crate) setter: Rc<dyn Fn(T)>,
|
pub(crate) setter: Rc<dyn Fn(T)>,
|
||||||
pub(crate) slot: Rc<RefCell<Rc<T>>>,
|
pub(crate) slot: Rc<RefCell<Rc<T>>>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use gloo::history::{BrowserHistory, History, HistoryListener, Location};
|
|||||||
use std::{
|
use std::{
|
||||||
cell::{Cell, Ref, RefCell},
|
cell::{Cell, Ref, RefCell},
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
rc::Rc,
|
rc::Rc, sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use dioxus_core::ScopeId;
|
use dioxus_core::ScopeId;
|
||||||
@@ -10,7 +10,7 @@ use dioxus_core::ScopeId;
|
|||||||
use crate::platform::RouterProvider;
|
use crate::platform::RouterProvider;
|
||||||
|
|
||||||
pub struct RouterService {
|
pub struct RouterService {
|
||||||
pub(crate) regen_route: Rc<dyn Fn(ScopeId)>,
|
pub(crate) regen_route: Arc<dyn Fn(ScopeId)>,
|
||||||
pub(crate) pending_events: Rc<RefCell<Vec<RouteEvent>>>,
|
pub(crate) pending_events: Rc<RefCell<Vec<RouteEvent>>>,
|
||||||
slots: Rc<RefCell<Vec<(ScopeId, String)>>>,
|
slots: Rc<RefCell<Vec<(ScopeId, String)>>>,
|
||||||
onchange_listeners: Rc<RefCell<HashSet<ScopeId>>>,
|
onchange_listeners: Rc<RefCell<HashSet<ScopeId>>>,
|
||||||
@@ -42,7 +42,7 @@ enum RouteSlot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RouterService {
|
impl RouterService {
|
||||||
pub fn new(regen_route: Rc<dyn Fn(ScopeId)>, root_scope: ScopeId) -> Self {
|
pub fn new(regen_route: Arc<dyn Fn(ScopeId)>, root_scope: ScopeId) -> Self {
|
||||||
let history = BrowserHistory::default();
|
let history = BrowserHistory::default();
|
||||||
let location = history.location();
|
let location = history.location();
|
||||||
let path = location.path();
|
let path = location.path();
|
||||||
|
|||||||
Reference in new issue
Block a user