Remove storage feature

This commit is contained in:
Joshua McQuistan 2023-10-27 14:27:53 +01:00
parent 7bfd069047
commit 7b5456a461
7 changed files with 26 additions and 52 deletions

View file

@ -84,6 +84,7 @@ features = [
"ServiceWorkerRegistration",
"ServiceWorkerState",
"Storage",
"StorageEvent",
"Touch",
"TouchEvent",
"TouchList",
@ -95,7 +96,6 @@ features = [
[features]
docs = []
math = ["num"]
storage = ["base64", "serde", "serde_json", "web-sys/StorageEvent"]
ssr = []
[package.metadata.docs.rs]

View file

@ -15,7 +15,7 @@ leptos = { version = "0.5", features = ["nightly"] }
leptos_axum = { version = "0.5", optional = true }
leptos_meta = { version = "0.5", features = ["nightly"] }
leptos_router = { version = "0.5", features = ["nightly"] }
leptos-use = { path = "../..", features = ["storage"] }
leptos-use = { path = "../.." }
log = "0.4"
simple_logger = "4"
tokio = { version = "1.25.0", optional = true }

View file

@ -8,7 +8,7 @@ leptos = { version = "0.5", features = ["nightly", "csr"] }
console_error_panic_hook = "0.1"
console_log = "1"
log = "0.4"
leptos-use = { path = "../..", features = ["docs", "storage"] }
leptos-use = { path = "../..", features = ["docs"] }
web-sys = "0.3"
[dev-dependencies]

View file

@ -8,7 +8,7 @@ leptos = { version = "0.5", features = ["nightly", "csr"] }
console_error_panic_hook = "0.1"
console_log = "1"
log = "0.4"
leptos-use = { path = "../..", features = ["docs", "storage"] }
leptos-use = { path = "../..", features = ["docs", "prost", "serde"] }
web-sys = "0.3"
serde = "1.0.163"

View file

@ -2,7 +2,6 @@ use leptos::window;
use wasm_bindgen::JsValue;
/// Local or session storage or a custom store that is a `web_sys::Storage`.
// #[doc(cfg(feature = "storage"))]
#[derive(Default)]
pub enum StorageType {
#[default]

View file

@ -1,4 +1,3 @@
#[cfg(feature = "storage")]
mod use_storage;
pub use use_storage::*;

View file

@ -1,13 +1,9 @@
use crate::core::{ElementMaybeSignal, MaybeRwSignal};
#[cfg(feature = "storage")]
use crate::storage::{use_storage_with_options, UseStorageOptions};
#[cfg(feature = "storage")]
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
use crate::core::StorageType;
use crate::use_preferred_dark;
use cfg_if::cfg_if;
use default_struct_builder::DefaultBuilder;
use leptos::*;
use std::marker::PhantomData;
@ -255,49 +251,29 @@ pub enum ColorMode {
Custom(String),
}
cfg_if! { if #[cfg(feature = "storage")] {
fn get_store_signal(
initial_value: MaybeRwSignal<ColorMode>,
storage_signal: Option<RwSignal<ColorMode>>,
storage_key: &str,
storage_enabled: bool,
storage: StorageType,
listen_to_storage_changes: bool,
) -> (Signal<ColorMode>, WriteSignal<ColorMode>) {
if let Some(storage_signal) = storage_signal {
let (store, set_store) = storage_signal.split();
(store.into(), set_store)
} else if storage_enabled {
let (store, set_store, _) = use_storage_with_options(
storage_key,
initial_value,
UseStorageOptions::default()
.listen_to_storage_changes(listen_to_storage_changes)
.storage_type(storage),
);
(store, set_store)
} else {
initial_value.into_signal()
}
fn get_store_signal(
initial_value: MaybeRwSignal<ColorMode>,
storage_signal: Option<RwSignal<ColorMode>>,
storage_key: &str,
storage_enabled: bool,
storage: StorageType,
listen_to_storage_changes: bool,
) -> (Signal<ColorMode>, WriteSignal<ColorMode>) {
if let Some(storage_signal) = storage_signal {
let (store, set_store) = storage_signal.split();
(store.into(), set_store)
} else if storage_enabled {
use_storage_with_options(
storage_key,
initial_value,
UseStorageOptions::default()
.listen_to_storage_changes(listen_to_storage_changes)
.storage_type(storage),
)
} else {
initial_value.into_signal()
}
} else {
fn get_store_signal(
initial_value: MaybeRwSignal<ColorMode>,
storage_signal: Option<RwSignal<ColorMode>>,
_storage_key: &str,
_storage_enabled: bool,
_storage: StorageType,
_listen_to_storage_changes: bool,
) -> (Signal<ColorMode>, WriteSignal<ColorMode>) {
if let Some(storage_signal) = storage_signal {
let (store, set_store) = storage_signal.split();
(store.into(), set_store)
} else {
initial_value.into_signal()
}
}
}}
}
impl Display for ColorMode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {