Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ utils = ["gloo-utils"]
history = ["gloo-history"]
worker = ["gloo-worker"]
net = ["gloo-net"]
wasi = ["gloo-history/wasi"]

[workspace]
members = [
Expand Down
1 change: 1 addition & 0 deletions crates/history/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ gloo-timers = { version = "0.3.0", features = ["futures"], path = "../timers" }

[features]
query = ["thiserror", "serde_urlencoded"]
wasi = []
default = ["query"]
14 changes: 12 additions & 2 deletions crates/history/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ use std::cell::RefCell;
use std::rc::{Rc, Weak};
use std::sync::atomic::{AtomicU32, Ordering};

#[cfg(not(feature = "wasi"))]
use wasm_bindgen::throw_str;

#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "wasi"))]
pub(crate) fn get_id() -> u32 {
static ID_CTR: AtomicU32 = AtomicU32::new(0);

ID_CTR.fetch_add(1, Ordering::SeqCst)
}

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(feature = "wasi")))]
pub(crate) fn get_id() -> u32 {
static ID_CTR: AtomicU32 = AtomicU32::new(0);
static INIT: std::sync::Once = std::sync::Once::new();
Expand All @@ -30,19 +31,28 @@ pub(crate) fn get_id() -> u32 {

pub(crate) fn assert_absolute_path(path: &str) {
if !path.starts_with('/') {
#[cfg(not(feature = "wasi"))]
throw_str("You cannot use relative path with this history type.");
#[cfg(feature = "wasi")]
panic!("You cannot use relative path with this history type.");
}
}

pub(crate) fn assert_no_query(path: &str) {
if path.contains('?') {
#[cfg(not(feature = "wasi"))]
throw_str("You cannot have query in path, try use a variant of this method with `_query`.");
#[cfg(feature = "wasi")]
panic!("You cannot have query in path, try use a variant of this method with `_query`.");
}
}

pub(crate) fn assert_no_fragment(path: &str) {
if path.contains('#') {
#[cfg(not(feature = "wasi"))]
throw_str("You cannot use fragments (hash) in memory history.");
#[cfg(feature = "wasi")]
panic!("You cannot use fragments (hash) in memory history.");
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/history/tests/query.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![cfg(feature = "query")]

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(feature = "wasi")))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(feature = "wasi")))]
wasm_bindgen_test_configure!(run_in_browser);

use gloo_history::query::*;
Expand Down