chore: make warnings go away
This commit is contained in:
1 parent
0027cdd938
commit
7c3d308ab5
34 files changed
+901
-810
No files matched your search
@@ -1,29 +1,19 @@
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use std::cell::RefCell;
|
||||
|
||||
use crate::{ScopeId, ScopeState};
|
||||
use crate::ScopeId;
|
||||
|
||||
pub struct ErrorContext {
|
||||
/// A boundary that will capture any errors from child components
|
||||
#[allow(dead_code)]
|
||||
pub struct ErrorBoundary {
|
||||
error: RefCell<Option<(anyhow::Error, ScopeId)>>,
|
||||
id: ScopeId,
|
||||
}
|
||||
|
||||
/// Catch all errors from the children and bubble them up to this component
|
||||
///
|
||||
/// Returns the error and scope that caused the error
|
||||
pub fn use_catch_error(cx: &ScopeState) -> Option<&(anyhow::Error, ScopeId)> {
|
||||
let err_ctx = use_error_context(cx);
|
||||
|
||||
let out = cx.use_hook(|| None);
|
||||
|
||||
if let Some(error) = err_ctx.error.take() {
|
||||
*out = Some(error);
|
||||
impl ErrorBoundary {
|
||||
pub fn new(id: ScopeId) -> Self {
|
||||
Self {
|
||||
error: RefCell::new(None),
|
||||
id,
|
||||
}
|
||||
}
|
||||
|
||||
out.as_ref()
|
||||
}
|
||||
|
||||
/// Create a new error context at this component.
|
||||
///
|
||||
/// This component will start to catch any errors that occur in its children.
|
||||
pub fn use_error_context(cx: &ScopeState) -> &ErrorContext {
|
||||
cx.use_hook(|| cx.provide_context(Rc::new(ErrorContext { error: None.into() })))
|
||||
}
|
||||
Reference in new issue
Block a user