Move the document trait into a separate crate (#3035)
* add a default head method through eval * remove the old document trait * implement document for each platform * pull out document into a dedicated crate to cut down on shared dependencies --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
1 parent
2b219c826c
commit
519ec9d294
91 files changed
+1113
-1044
No files matched your search
@@ -0,0 +1,31 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
mod document;
|
||||
mod elements;
|
||||
mod error;
|
||||
mod eval;
|
||||
|
||||
pub use document::*;
|
||||
pub use elements::*;
|
||||
pub use error::*;
|
||||
pub use eval::*;
|
||||
|
||||
/// Get the document provider for the current platform or a no-op provider if the platform doesn't document functionality.
|
||||
pub fn document() -> Rc<dyn Document> {
|
||||
match dioxus_core::prelude::try_consume_context::<Rc<dyn Document>>() {
|
||||
Some(document) => document,
|
||||
None => {
|
||||
tracing::error!(
|
||||
"Unable to find a document in the renderer. Using the default no-op document."
|
||||
);
|
||||
Rc::new(NoOpDocument)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Evaluate some javascript in the current document
|
||||
#[doc = include_str!("../docs/eval.md")]
|
||||
#[doc(alias = "javascript")]
|
||||
pub fn eval(script: &str) -> Eval {
|
||||
document().eval(script.to_string())
|
||||
}
|
||||
Reference in new issue
Block a user