Skip to content

Commit

Permalink
Remove the flags what to expect WASI targets. (#425)
Browse files Browse the repository at this point in the history
* Remove the flags what to expect WASI targets.

* Try to fix web_sys imports.

* Fix pub mod.

* Remove macro on the header.
It's my fault...

* Update crates/history/Cargo.toml

Co-authored-by: Kaede Hoshikawa <futursolo@users.noreply.github.com>

---------

Co-authored-by: Kaede Hoshikawa <futursolo@users.noreply.github.com>
  • Loading branch information
langyo and futursolo authored Dec 10, 2023
1 parent 5f96627 commit 3193cd6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 40 deletions.
6 changes: 2 additions & 4 deletions crates/history/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ serde = { version = "1", features = ["derive"] }
serde-wasm-bindgen = "0.6.0"
serde_urlencoded = { version = "0.7", optional = true }
thiserror = { version = "1.0", optional = true }
wasm-bindgen = "0.2.88"

[target.'cfg(not(target_os = "wasi"))'.dependencies]
wasm-bindgen = "0.2"

[target.'cfg(not(target_os = "wasi"))'.dependencies.web-sys]
[dependencies.web-sys]
version = "0.3"
features = ["History", "Window", "Location", "Url"]

Expand Down
42 changes: 12 additions & 30 deletions crates/history/src/any.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::borrow::Cow;

#[cfg(not(target_os = "wasi"))]
use crate::browser::BrowserHistory;
#[cfg(not(target_os = "wasi"))]
use crate::hash::HashHistory;
use crate::history::History;
use crate::listener::HistoryListener;
Expand All @@ -15,10 +13,8 @@ use crate::{error::HistoryResult, query::ToQuery};
#[derive(Clone, PartialEq, Debug)]
pub enum AnyHistory {
/// A Browser History.
#[cfg(not(target_os = "wasi"))]
Browser(BrowserHistory),
/// A Hash History
#[cfg(not(target_os = "wasi"))]
Hash(HashHistory),
/// A Memory History
Memory(MemoryHistory),
Expand All @@ -27,39 +23,35 @@ pub enum AnyHistory {
impl History for AnyHistory {
fn len(&self) -> usize {
match self {
#[cfg(not(target_os = "wasi"))]
Self::Browser(m) => m.len(),
#[cfg(not(target_os = "wasi"))]

Self::Hash(m) => m.len(),
Self::Memory(m) => m.len(),
}
}

fn go(&self, delta: isize) {
match self {
#[cfg(not(target_os = "wasi"))]
Self::Browser(m) => m.go(delta),
#[cfg(not(target_os = "wasi"))]

Self::Hash(m) => m.go(delta),
Self::Memory(m) => m.go(delta),
}
}

fn push<'a>(&self, route: impl Into<Cow<'a, str>>) {
match self {
#[cfg(not(target_os = "wasi"))]
Self::Browser(m) => m.push(route),
#[cfg(not(target_os = "wasi"))]

Self::Hash(m) => m.push(route),
Self::Memory(m) => m.push(route),
}
}

fn replace<'a>(&self, route: impl Into<Cow<'a, str>>) {
match self {
#[cfg(not(target_os = "wasi"))]
Self::Browser(m) => m.replace(route),
#[cfg(not(target_os = "wasi"))]

Self::Hash(m) => m.replace(route),
Self::Memory(m) => m.replace(route),
}
Expand All @@ -70,9 +62,8 @@ impl History for AnyHistory {
T: 'static,
{
match self {
#[cfg(not(target_os = "wasi"))]
Self::Browser(m) => m.push_with_state(route, state),
#[cfg(not(target_os = "wasi"))]

Self::Hash(m) => m.push_with_state(route, state),
Self::Memory(m) => m.push_with_state(route, state),
}
Expand All @@ -83,9 +74,8 @@ impl History for AnyHistory {
T: 'static,
{
match self {
#[cfg(not(target_os = "wasi"))]
Self::Browser(m) => m.replace_with_state(route, state),
#[cfg(not(target_os = "wasi"))]

Self::Hash(m) => m.replace_with_state(route, state),
Self::Memory(m) => m.replace_with_state(route, state),
}
Expand All @@ -101,9 +91,8 @@ impl History for AnyHistory {
Q: ToQuery,
{
match self {
#[cfg(not(target_os = "wasi"))]
Self::Browser(m) => m.push_with_query(route, query),
#[cfg(not(target_os = "wasi"))]

Self::Hash(m) => m.push_with_query(route, query),
Self::Memory(m) => m.push_with_query(route, query),
}
Expand All @@ -118,9 +107,8 @@ impl History for AnyHistory {
Q: ToQuery,
{
match self {
#[cfg(not(target_os = "wasi"))]
Self::Browser(m) => m.replace_with_query(route, query),
#[cfg(not(target_os = "wasi"))]

Self::Hash(m) => m.replace_with_query(route, query),
Self::Memory(m) => m.replace_with_query(route, query),
}
Expand All @@ -138,9 +126,8 @@ impl History for AnyHistory {
T: 'static,
{
match self {
#[cfg(not(target_os = "wasi"))]
Self::Browser(m) => m.push_with_query_and_state(route, query, state),
#[cfg(not(target_os = "wasi"))]

Self::Hash(m) => m.push_with_query_and_state(route, query, state),
Self::Memory(m) => m.push_with_query_and_state(route, query, state),
}
Expand All @@ -158,9 +145,8 @@ impl History for AnyHistory {
T: 'static,
{
match self {
#[cfg(not(target_os = "wasi"))]
Self::Browser(m) => m.replace_with_query_and_state(route, query, state),
#[cfg(not(target_os = "wasi"))]

Self::Hash(m) => m.replace_with_query_and_state(route, query, state),
Self::Memory(m) => m.replace_with_query_and_state(route, query, state),
}
Expand All @@ -171,33 +157,29 @@ impl History for AnyHistory {
CB: Fn() + 'static,
{
match self {
#[cfg(not(target_os = "wasi"))]
Self::Browser(m) => m.listen(callback),
#[cfg(not(target_os = "wasi"))]

Self::Hash(m) => m.listen(callback),
Self::Memory(m) => m.listen(callback),
}
}

fn location(&self) -> Location {
match self {
#[cfg(not(target_os = "wasi"))]
Self::Browser(m) => m.location(),
#[cfg(not(target_os = "wasi"))]

Self::Hash(m) => m.location(),
Self::Memory(m) => m.location(),
}
}
}

#[cfg(not(target_os = "wasi"))]
impl From<BrowserHistory> for AnyHistory {
fn from(m: BrowserHistory) -> AnyHistory {
AnyHistory::Browser(m)
}
}

#[cfg(not(target_os = "wasi"))]
impl From<HashHistory> for AnyHistory {
fn from(m: HashHistory) -> AnyHistory {
AnyHistory::Hash(m)
Expand Down
4 changes: 0 additions & 4 deletions crates/history/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
#![deny(missing_docs, missing_debug_implementations)]

mod any;
#[cfg(not(target_os = "wasi"))]
mod browser;
#[cfg(feature = "query")]
mod error;
#[cfg(not(target_os = "wasi"))]
mod hash;
mod history;
mod listener;
Expand All @@ -20,9 +18,7 @@ mod state;
mod utils;

pub use any::AnyHistory;
#[cfg(not(target_os = "wasi"))]
pub use browser::BrowserHistory;
#[cfg(not(target_os = "wasi"))]
pub use hash::HashHistory;
pub use memory::MemoryHistory;

Expand Down
2 changes: 0 additions & 2 deletions crates/history/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(not(target_os = "wasi"))]

use std::any::Any;
use std::collections::HashMap;
use std::rc::Rc;
Expand Down

0 comments on commit 3193cd6

Please sign in to comment.