mirror of
https://github.com/adoyle0/leptos-use.git
synced 2025-01-23 09:09:21 -05:00
Remove storage feature
This commit is contained in:
parent
7bfd069047
commit
7b5456a461
7 changed files with 26 additions and 52 deletions
|
@ -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]
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#[cfg(feature = "storage")]
|
||||
mod use_storage;
|
||||
|
||||
pub use use_storage::*;
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue