make eval copy
This commit is contained in:
1 parent
894a79d3df
commit
a789d6a64e
13 files changed
+191
-107
No files matched your search
+16
-12
@@ -1,6 +1,7 @@
|
||||
use async_trait::async_trait;
|
||||
use dioxus_core::ScopeId;
|
||||
use dioxus_html::prelude::{EvalError, EvalProvider, Evaluator};
|
||||
use generational_box::{AnyStorage, GenerationalBox, UnsyncStorage};
|
||||
use std::rc::Rc;
|
||||
|
||||
/// Provides the SSREvalProvider through [`cx.provide_context`].
|
||||
@@ -12,8 +13,9 @@ pub fn init_eval() {
|
||||
/// Reprents the ssr-target's provider of evaluators.
|
||||
pub struct SSREvalProvider;
|
||||
impl EvalProvider for SSREvalProvider {
|
||||
fn new_evaluator(&self, _: String) -> Result<Box<dyn Evaluator>, EvalError> {
|
||||
Ok(Box::new(SSREvaluator) as Box<dyn Evaluator + 'static>)
|
||||
fn new_evaluator(&self, _: String) -> Result<GenerationalBox<Box<dyn Evaluator>>, EvalError> {
|
||||
let owner = UnsyncStorage::owner();
|
||||
Ok(owner.insert(Box::new(SSREvaluator) as Box<dyn Evaluator + 'static>))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,20 +25,22 @@ pub struct SSREvaluator;
|
||||
// In ssr rendering we never run or resolve evals.
|
||||
#[async_trait(?Send)]
|
||||
impl Evaluator for SSREvaluator {
|
||||
/// Runs the evaluated JavaScript.
|
||||
async fn join(&self) -> Result<serde_json::Value, EvalError> {
|
||||
std::future::pending::<()>().await;
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
/// Sends a message to the evaluated JavaScript.
|
||||
fn send(&self, _el: serde_json::Value) -> Result<(), EvalError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Gets an UnboundedReceiver to receive messages from the evaluated JavaScript.
|
||||
async fn recv(&mut self) -> Result<serde_json::Value, EvalError> {
|
||||
std::future::pending::<()>().await;
|
||||
unreachable!()
|
||||
fn poll_recv(
|
||||
&mut self,
|
||||
_cx: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<Result<serde_json::Value, EvalError>> {
|
||||
std::task::Poll::Pending
|
||||
}
|
||||
|
||||
fn poll_join(
|
||||
&mut self,
|
||||
_cx: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<Result<serde_json::Value, EvalError>> {
|
||||
std::task::Poll::Pending
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user