don't expose the signal scope subscriber API publicly
This commit is contained in:
1 parent
30bac267c9
commit
91fea15cdc
4 files changed
+18
-7
No files matched your search
@@ -11,7 +11,7 @@ pub fn use_effect(mut callback: impl FnMut() + 'static) {
|
|||||||
|
|
||||||
use_hook(|| {
|
use_hook(|| {
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
let rc = ReactiveContext::new(None);
|
let rc = ReactiveContext::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Wait for the dom the be finished with sync work
|
// Wait for the dom the be finished with sync work
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ pub fn use_maybe_sync_memo<R: PartialEq, S: Storage<SignalData<R>>>(
|
|||||||
) -> ReadOnlySignal<R, S> {
|
) -> ReadOnlySignal<R, S> {
|
||||||
use_hook(|| {
|
use_hook(|| {
|
||||||
// Get the current reactive context
|
// Get the current reactive context
|
||||||
let rc = ReactiveContext::new(None);
|
let rc = ReactiveContext::new();
|
||||||
|
|
||||||
// Create a new signal in that context, wiring up its dependencies and subscribers
|
// Create a new signal in that context, wiring up its dependencies and subscribers
|
||||||
let mut state: Signal<R, S> = rc.run_in(|| Signal::new_maybe_sync(f()));
|
let mut state: Signal<R, S> = rc.run_in(|| Signal::new_maybe_sync(f()));
|
||||||
@@ -129,7 +129,7 @@ where
|
|||||||
|
|
||||||
let selector = use_hook(|| {
|
let selector = use_hook(|| {
|
||||||
// Get the current reactive context
|
// Get the current reactive context
|
||||||
let rc = ReactiveContext::new(None);
|
let rc = ReactiveContext::new();
|
||||||
|
|
||||||
// Create a new signal in that context, wiring up its dependencies and subscribers
|
// Create a new signal in that context, wiring up its dependencies and subscribers
|
||||||
let mut state: Signal<R, S> =
|
let mut state: Signal<R, S> =
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ where
|
|||||||
{
|
{
|
||||||
let mut value = use_signal(|| None);
|
let mut value = use_signal(|| None);
|
||||||
let mut state = use_signal(|| UseResourceState::Pending);
|
let mut state = use_signal(|| UseResourceState::Pending);
|
||||||
let rc = use_hook(|| ReactiveContext::new(None));
|
let rc = use_hook(ReactiveContext::new);
|
||||||
|
|
||||||
let mut cb = use_callback(move || {
|
let mut cb = use_callback(move || {
|
||||||
// Create the user's task
|
// Create the user's task
|
||||||
|
|||||||
@@ -22,9 +22,20 @@ thread_local! {
|
|||||||
static CURRENT: RefCell<Vec<ReactiveContext>> = const { RefCell::new(vec![]) };
|
static CURRENT: RefCell<Vec<ReactiveContext>> = const { RefCell::new(vec![]) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ReactiveContext {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new_for_scope(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ReactiveContext {
|
impl ReactiveContext {
|
||||||
/// Create a new reactive context
|
/// Create a new reactive context
|
||||||
pub fn new(scope: Option<ScopeId>) -> Self {
|
pub fn new() -> Self {
|
||||||
|
Self::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a new reactive context that may update a scope
|
||||||
|
pub(crate) fn new_for_scope(scope: Option<ScopeId>) -> Self {
|
||||||
let (tx, rx) = flume::unbounded();
|
let (tx, rx) = flume::unbounded();
|
||||||
|
|
||||||
let mut scope_subscribers = FxHashSet::default();
|
let mut scope_subscribers = FxHashSet::default();
|
||||||
@@ -56,7 +67,7 @@ impl ReactiveContext {
|
|||||||
///
|
///
|
||||||
/// If this was set manually, then that value will be returned.
|
/// If this was set manually, then that value will be returned.
|
||||||
///
|
///
|
||||||
/// If there's no current reactive context, then a new one will be created at the current scope and returned.
|
/// If there's no current reactive context, then a new one will be created for the current scope and returned.
|
||||||
pub fn current() -> Self {
|
pub fn current() -> Self {
|
||||||
let cur = CURRENT.with(|current| current.borrow().last().cloned());
|
let cur = CURRENT.with(|current| current.borrow().last().cloned());
|
||||||
|
|
||||||
@@ -71,7 +82,7 @@ impl ReactiveContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, create a new context at the current scope
|
// Otherwise, create a new context at the current scope
|
||||||
provide_context(ReactiveContext::new(current_scope_id()))
|
provide_context(ReactiveContext::new_for_scope(current_scope_id()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run this function in the context of this reactive context
|
/// Run this function in the context of this reactive context
|
||||||
|
|||||||
Reference in new issue
Block a user