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:
Evan AlmloffandJonathan Kelley authored and GitHub committed 2024-10-14 10:33:37 -07:00
1 parent 2b219c826c
commit 519ec9d294
91 files changed
+1113 -1044

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ use std::time::Duration;
use dioxus_core::ScopeId;
use dioxus_devtools::{DevserverMsg, HotReloadMsg};
use dioxus_html::prelude::eval;
use dioxus_document::eval;
use futures_channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender};
use js_sys::JsString;
use wasm_bindgen::JsCast;
+6 -14
View File
@@ -1,5 +1,5 @@
use dioxus_core::ScopeId;
use dioxus_html::document::{Document, EvalError, Evaluator, NoOpEvaluator};
use dioxus_document::{Document, Eval, EvalError, Evaluator};
use generational_box::{AnyStorage, GenerationalBox, UnsyncStorage};
use js_sys::Function;
use serde::Serialize;
@@ -64,12 +64,8 @@ pub fn init_document() {
/// The web-target's document provider.
pub struct WebDocument;
impl Document for WebDocument {
fn new_evaluator(&self, js: String) -> GenerationalBox<Box<dyn Evaluator>> {
WebEvaluator::create(js)
}
fn as_any(&self) -> &dyn std::any::Any {
self
fn eval(&self, js: String) -> Eval {
Eval::new(WebEvaluator::create(js))
}
}
@@ -95,10 +91,8 @@ impl WebEvaluator {
fn create(js: String) -> GenerationalBox<Box<dyn Evaluator>> {
let owner = UnsyncStorage::owner();
let generational_box = owner.insert(Box::new(NoOpEvaluator) as Box<dyn Evaluator>);
// add the drop handler to DioxusChannel so that it gets dropped when the channel is dropped in js
let channels = WebDioxusChannel::new(JSOwner::new(owner));
let channels = WebDioxusChannel::new(JSOwner::new(owner.clone()));
// The Rust side of the channel is a weak reference to the DioxusChannel
let weak_channels = channels.weak();
@@ -131,13 +125,11 @@ impl WebEvaluator {
)),
};
generational_box.set(Box::new(Self {
owner.insert(Box::new(Self {
channels: weak_channels,
result: Some(result),
next_future: None,
}) as Box<dyn Evaluator>);
generational_box
}) as Box<dyn Evaluator>)
}
}
+1 -1
View File
@@ -1 +1 @@
[3479327739946104450]
[1614426347475783279]
+1 -1
View File
@@ -2,7 +2,7 @@ import {
DioxusChannel,
Channel,
WeakDioxusChannel,
} from "../../../html/src/ts/eval";
} from "../../../document/src/ts/eval";
export class WebDioxusChannel extends DioxusChannel {
js_to_rust: Channel;