Browse Source

clean up some core context APIs

Evan Almloff 1 year ago
parent
commit
6c29e2b825

+ 2 - 2
packages/core/src/global_context.rs

@@ -38,8 +38,8 @@ pub fn has_context<T: 'static + Clone>() -> Option<T> {
 }
 }
 
 
 /// Provide context to the current scope
 /// Provide context to the current scope
-pub fn provide_context<T: 'static + Clone>(value: T) -> Option<T> {
-    with_current_scope(|cx| cx.provide_context(value))
+pub fn provide_context<T: 'static + Clone>(value: T) -> T {
+    with_current_scope(|cx| cx.provide_context(value)).expect("to be in a dioxus runtime")
 }
 }
 
 
 /// Provide a context to the root scope
 /// Provide a context to the root scope

+ 2 - 2
packages/core/src/scope_context.rs

@@ -338,8 +338,8 @@ impl ScopeId {
     }
     }
 
 
     /// Provide context to the current scope
     /// Provide context to the current scope
-    pub fn provide_context<T: 'static + Clone>(self, value: T) -> Option<T> {
-        with_scope(self, |cx| cx.provide_context(value))
+    pub fn provide_context<T: 'static + Clone>(self, value: T) -> T {
+        with_scope(self, |cx| cx.provide_context(value)).expect("to be in a dioxus runtime")
     }
     }
 
 
     /// Suspends the current component
     /// Suspends the current component

+ 2 - 2
packages/signals/src/rt.rs

@@ -33,7 +33,7 @@ fn current_owner() -> Rc<Owner> {
             Some(rt) => rt,
             Some(rt) => rt,
             None => {
             None => {
                 let owner = Rc::new(current_store().owner());
                 let owner = Rc::new(current_store().owner());
-                provide_context(owner).expect("in a virtual dom")
+                provide_context(owner)
             }
             }
         },
         },
     }
     }
@@ -44,7 +44,7 @@ fn owner_in_scope(scope: ScopeId) -> Rc<Owner> {
         Some(rt) => rt,
         Some(rt) => rt,
         None => {
         None => {
             let owner = Rc::new(current_store().owner());
             let owner = Rc::new(current_store().owner());
-            scope.provide_context(owner).expect("in a virtual dom")
+            scope.provide_context(owner)
         }
         }
     }
     }
 }
 }

+ 1 - 1
packages/signals/src/signal.rs

@@ -85,7 +85,7 @@ fn current_unsubscriber() -> Unsubscriber {
                 scope: current_scope_id().expect("in a virtual dom"),
                 scope: current_scope_id().expect("in a virtual dom"),
                 subscribers: Default::default(),
                 subscribers: Default::default(),
             };
             };
-            provide_context(owner).expect("in a virtual dom")
+            provide_context(owner)
         }
         }
     }
     }
 }
 }