Feat: add global context functions

Add functions like window() and router() to
allow dynamically grabbing global contexts
without have to use the hook variants.

Deprecates the existing hook variants to
discourage folks from adding more noise
to their codebases.
This commit is contained in:
Jonathan Kelley committed 2023-10-23 16:26:10 -04:00
1 parent cea9563e25
commit dd4547d753
16 files changed
+77 -78

No files matched your search

+9
View File
@@ -48,6 +48,15 @@ pub fn use_eval(cx: &ScopeState) -> &EvalCreator {
})
}
pub fn eval(script: &str) -> Result<UseEval, EvalError> {
let eval_provider = dioxus_core::prelude::consume_context::<Rc<dyn EvalProvider>>()
.expect("evaluator not provided");
eval_provider
.new_evaluator(script.to_string())
.map(UseEval::new)
}
/// A wrapper around the target platform's evaluator.
#[derive(Clone)]
pub struct UseEval {