use crate::reactor::WindowVariable;
pub fn checkpoint(name: &str) {
if name.contains('-') {
panic!("checkpoint must not contain hyphens, use underscores instead (hyphens are used as an internal delimiter)");
}
let is_testing = WindowVariable::new_bool("__PERSEUS_TESTING");
match is_testing {
WindowVariable::Some(val) if val => (),
_ => return,
};
crate::web_log!("Perseus is in testing mode. If you're an end-user and seeing this message, please report this as a bug to the website owners!");
let document = web_sys::window().unwrap().document().unwrap();
let container_opt = document.query_selector("#__perseus_checkpoints").unwrap();
let container = match container_opt {
Some(container_i) => container_i,
None => {
let container = document.create_element("div").unwrap();
container.set_id("__perseus_checkpoints");
document
.query_selector("body")
.unwrap()
.unwrap()
.append_with_node_1(&container)
.unwrap();
container
}
};
let num_checkpoints = document
.query_selector_all(&format!("[id^=__perseus_checkpoint-{}-]", name))
.unwrap()
.length();
let checkpoint = document.create_element("div").unwrap();
checkpoint.set_id(&format!(
"__perseus_checkpoint-{}-{}",
name, num_checkpoints
));
container.append_with_node_1(&checkpoint).unwrap();
}