Merge branch 'main' into pr/add-console-panic-hooks

This commit is contained in:
Greg Johnston 2022-10-20 17:51:40 -04:00 committed by GitHub
commit af152891a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 47 additions and 23 deletions

View file

@ -5,6 +5,7 @@ edition = "2021"
[dependencies]
leptos = { path = "../../leptos" }
console_error_panic_hook = "0.1"
console_log = "0.2"
log = "0.4"
console_error_panic_hook = "0.1.7"

View file

@ -2,7 +2,7 @@ use counter::simple_counter;
use leptos::*;
pub fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
// _ = console_log::init_with_level(log::Level::Debug);
mount_to_body(simple_counter)
}

View file

@ -5,6 +5,7 @@ edition = "2021"
[dependencies]
leptos = { path = "../../leptos", features = ["stable"] }
console_error_panic_hook = "0.1"
log = "0.4"
console_log = "0.2"
console_error_panic_hook = "0.1.7"

View file

@ -3,6 +3,7 @@ use leptos::*;
fn main() {
console_error_panic_hook::set_once();
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(|cx| view! { cx, <Counters/> })
}

View file

@ -5,6 +5,7 @@ edition = "2021"
[dependencies]
leptos = { path = "../../leptos" }
console_error_panic_hook = "0.1"
log = "0.4"
console_log = "0.2"
console_error_panic_hook = "0.1.7"

View file

@ -4,5 +4,6 @@ use leptos::*;
fn main() {
console_error_panic_hook::set_once();
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(|cx| view! { cx, <Counters/> })
}

View file

@ -5,6 +5,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0.58"
console_error_panic_hook = "0.1"
leptos = { path = "../../leptos" }
reqwasm = "0.5.0"
serde = { version = "1", features = ["derive"] }

View file

@ -4,6 +4,6 @@ use leptos::*;
pub fn main() {
console_error_panic_hook::set_once();
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(fetch_example)
}

View file

@ -5,6 +5,7 @@ edition = "2021"
[dependencies]
anyhow = "1"
console_error_panic_hook = "0.1"
console_log = "0.2"
leptos = { path = "../../../leptos", default-features = false }
leptos_meta = { path = "../../../meta", default-features = false }

View file

@ -4,6 +4,7 @@ use leptos::*;
pub fn main() {
console_error_panic_hook::set_once();
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(|cx| {
view! { cx, <App/> }
});

View file

@ -8,6 +8,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
console_log = "0.2"
console_error_panic_hook = "0.1"
hackernews-app = { path = "../hackernews-app", default-features = false, features = ["hydrate"] }
leptos = { path = "../../../leptos", default-features = false, features = ["hydrate"] }
log = "0.4"

View file

@ -5,6 +5,7 @@ use wasm_bindgen::prelude::wasm_bindgen;
#[wasm_bindgen]
pub fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
leptos::hydrate(body().unwrap(), move |cx| {
view! { cx, <App/> }
});

View file

@ -5,6 +5,7 @@ edition = "2021"
[dependencies]
leptos = { path = "../../leptos" }
console_error_panic_hook = "0.1"
console_log = "0.2"
log = "0.4"
console_error_panic_hook = "0.1.7"

View file

@ -2,7 +2,7 @@ use leptos::*;
use parent_child::*;
pub fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
// _ = console_log::init_with_level(log::Level::Debug);
mount_to_body(|cx| view! { cx, <App/> })
}

View file

@ -5,6 +5,7 @@ edition = "2021"
[dependencies]
console_log = "0.2"
console_error_panic_hook = "0.1"
log = "0.4"
leptos = { path = "../../leptos" }
leptos_router = { path = "../../router" }

View file

@ -4,5 +4,6 @@ use router::router_example;
pub fn main() {
console_error_panic_hook::set_once();
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(router_example)
}

View file

@ -8,6 +8,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
console_log = "0.2"
console_error_panic_hook = "0.1"
leptos = { path = "../../../leptos", default-features = false, features = ["hydrate"] }
todomvc = { path = "../../todomvc", default-features = false, features = ["hydrate"] }
log = "0.4"

View file

@ -6,6 +6,7 @@ use wasm_bindgen::prelude::wasm_bindgen;
pub fn main() {
console_error_panic_hook::set_once();
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
log::debug!("initialized logging");
leptos::hydrate(body().unwrap(), |cx| {

View file

@ -5,6 +5,7 @@ edition = "2021"
[dependencies]
leptos = { path = "../../leptos", default-features = false }
console_error_panic_hook = "0.1"
miniserde = "0.1"
log = "0.4"
console_log = "0.2"

View file

@ -3,5 +3,6 @@ pub use todomvc::*;
fn main() {
console_error_panic_hook::set_once();
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(|cx| view! { cx, <TodoMVC todos=Todos::new(cx)/> })
}

View file

@ -91,7 +91,8 @@ where
pub fn with<U>(&self, f: impl Fn(&T) -> U) -> U {
// okay to unwrap here, because the value will *always* have initially
// been set by the effect, synchronously
self.0.with(|n| f(n.as_ref().unwrap()))
self.0
.with(|n| f(n.as_ref().expect("Memo is missing its initial value")))
}
}

View file

@ -147,9 +147,8 @@ where
if let Some(data) = context.resolved_resources.remove(&id) {
context.pending_resources.remove(&id); // no longer pending
r.resolved.set(true);
//let decoded = base64::decode(&data).unwrap_throw();
//let res = bincode::deserialize(&decoded).unwrap_throw();
let res = serde_json::from_str(&data).unwrap_throw();
let res =
serde_json::from_str(&data).expect_throw("could not deserialize Resource JSON");
r.set_value.update(|n| *n = Some(res));
r.set_loading.update(|n| *n = false);
@ -163,9 +162,8 @@ where
let set_value = r.set_value;
let set_loading = r.set_loading;
move |res: String| {
//let decoded = base64::decode(&res).unwrap_throw();
//let res = bincode::deserialize(&decoded).unwrap_throw();
let res = serde_json::from_str(&res).unwrap_throw();
let res = serde_json::from_str(&res)
.expect_throw("could not deserialize JSON for already-resolved Resource");
resolved.set(true);
set_value.update(|n| *n = res);
set_loading.update(|n| *n = false);
@ -177,8 +175,8 @@ where
&web_sys::window().unwrap(),
&wasm_bindgen::JsValue::from_str("__LEPTOS_RESOURCE_RESOLVERS"),
)
.unwrap();
let id = serde_json::to_string(&id).unwrap();
.expect_throw("no __LEPTOS_RESOURCE_RESOLVERS found in the JS global scope");
let id = serde_json::to_string(&id).expect_throw("could not deserialize Resource ID");
_ = js_sys::Reflect::set(
&resource_resolvers,
&wasm_bindgen::JsValue::from_str(&id),
@ -418,8 +416,10 @@ where
let fut = (self.fetcher)(self.source.get());
Box::pin(async move {
let res = fut.await;
(id, serde_json::to_string(&res).unwrap())
//(id, base64::encode(&bincode::serialize(&res).unwrap()))
(
id,
serde_json::to_string(&res).expect("could not serialize Resource"),
)
})
}
}

View file

@ -166,7 +166,7 @@ impl Runtime {
for i in 0..templates.length() {
let node = templates
.item(i)
.unwrap_throw()
.unwrap_throw() // ok to unwrap; we already have the index, so this can't fail
.unchecked_into::<web_sys::Element>();
let key = node.get_attribute("data-hk").unwrap_throw();
registry.insert(key, node);

View file

@ -65,7 +65,11 @@ impl Scope {
pub fn child_scope(self, f: impl FnOnce(Scope)) -> ScopeDisposer {
let (_, child_id, disposer) = self.runtime.run_scope_undisposed(f, Some(self));
let mut children = self.runtime.scope_children.borrow_mut();
children.entry(self.id).unwrap().or_default().push(child_id);
children
.entry(self.id)
.expect("trying to add a child to a Scope that has already been disposed")
.or_default()
.push(child_id);
disposer
}
@ -145,7 +149,7 @@ pub fn on_cleanup(cx: Scope, cleanup_fn: impl FnOnce() + 'static) {
let mut cleanups = cx.runtime.scope_cleanups.borrow_mut();
let cleanups = cleanups
.entry(cx.id)
.unwrap()
.expect("trying to clean up a Scope that has already been disposed")
.or_insert_with(Default::default);
cleanups.push(Box::new(cleanup_fn));
}
@ -193,10 +197,10 @@ impl Scope {
.unchecked_ref::<web_sys::HtmlTemplateElement>()
.content()
.clone_node_with_deep(true)
.unwrap_throw()
.expect_throw("(get_next_element) could not clone template")
.unchecked_into::<web_sys::Element>()
.first_element_child()
.unwrap_throw();
.expect_throw("(get_next_element) could not get first child of template");
t
};

View file

@ -44,11 +44,10 @@ where
.downcast_ref::<T>()
.cloned()
.unwrap_or_else(|| {
debug_warn!(
panic!(
"use_loader() could not downcast to {:?}",
std::any::type_name::<T>(),
);
panic!()
)
})
}
},
@ -81,7 +80,10 @@ where
cx,
move || (params.get(), url()),
move |(params, url)| async move {
log::debug!("[LOADER] calling loader; should fire whenever params or URL change");
log::debug!(
"[LOADER] calling loader with {:#?}; should fire whenever params or URL change",
(params, url)
);
let route = use_route(cx);
let query = use_query_map(cx);