From 6abf62e21e2241a73bad8cdb4ca330f2a6b572c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kav=C3=ADk?= Date: Mon, 13 May 2019 23:55:29 +0200 Subject: [PATCH] 81-update-promises-fails --- src/vdom.rs | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/vdom.rs b/src/vdom.rs index 66eb00aab..0f6372b83 100644 --- a/src/vdom.rs +++ b/src/vdom.rs @@ -7,7 +7,6 @@ use futures::Future; use std::{ cell::RefCell, collections::{HashMap, vec_deque::VecDeque}, - panic, rc::Rc, }; use wasm_bindgen::closure::Closure; @@ -174,18 +173,10 @@ pub trait MountPoint { impl MountPoint for &str { fn element(self) -> Element { - // We log an error instead of relying on panic/except due to the panic hook not yet - // being active. - util::document().get_element_by_id(self).unwrap_or_else(|| { - let text = format!( - concat!( - "Can't find parent div with id={:?} (defaults to \"app\", or can be set with the .mount() method)", - ), - self, - ); - crate::error(&text); - panic!(text); - }) + util::document().get_element_by_id(self).expect( + &format!("Can't find element with id={:?} - app cannot be mounted!\n\ + (Id defaults to \"app\", or can be set with the .mount() method)", self) + ) } } @@ -274,6 +265,10 @@ impl + 'static> App { update: UpdateFn, view: ViewFn, ) -> AppBuilder { + + // Allows panic messages to output to the browser console.error. + console_error_panic_hook::set_once(); + AppBuilder { model, update, @@ -363,10 +358,6 @@ impl + 'static> App { ); routing::setup_link_listener(enclose!((self => s) move |msg| s.update(msg)), routes); } - - // Allows panic messages to output to the browser console.error. - panic::set_hook(Box::new(console_error_panic_hook::hook)); - self }