impl IntoView {
#[component]
fn TodoWithQuery() -> impl IntoView {
- let (todo_id, set_todo_id) = create_signal(TodoId(0));
+ let (todo_id, set_todo_id) = signal(TodoId(0));
let QueryResult { data, .. } = todo_query().use_query(move || todo_id.get());
@@ -156,7 +157,7 @@ fn AllTodos() -> impl IntoView {
let todos: Signal
> = Signal::derive(move || data.get().unwrap_or_default());
- create_effect(move |_| {
+ Effect::new(move |_| {
let state = state.get();
let log = match state {
QueryState::Created => "created",
@@ -168,7 +169,7 @@ fn AllTodos() -> impl IntoView {
logging::log!("STATE: {log}")
});
- let delete_todo = create_action(move |id: &TodoId| {
+ let delete_todo = Action::new(move |id: &TodoId| {
let id = *id;
let refetch = refetch.clone();
@@ -216,7 +217,7 @@ fn AllTodos() -> impl IntoView {
{todo.content}
" "
}
@@ -231,14 +232,14 @@ fn AllTodos() -> impl IntoView {
#[component]
fn AddTodoComponent() -> impl IntoView {
- let add_todo = create_server_action::();
+ let add_todo = ServerAction::::new();
let response = add_todo.value();
let todo_query = todo_query();
let all_todos = all_todos_query();
- create_effect(move |_| {
+ Effect::new(move |_| {
// If action is successful.
if let Some(Ok(todo)) = response.get() {
all_todos.cancel_query(AllTodosTag);
diff --git a/example/start-csr/src/components/header.rs b/example/start-csr/src/components/header.rs
index 855e760..0ccb95f 100644
--- a/example/start-csr/src/components/header.rs
+++ b/example/start-csr/src/components/header.rs
@@ -1,4 +1,4 @@
-use leptos::*;
+use leptos::prelude::*;
#[component]
pub fn Header(#[prop(optional, into)] title: String, children: ChildrenFn) -> impl IntoView {
diff --git a/example/start-csr/src/components/mod.rs b/example/start-csr/src/components/mod.rs
index 0cb0590..b83b140 100644
--- a/example/start-csr/src/components/mod.rs
+++ b/example/start-csr/src/components/mod.rs
@@ -1,4 +1,4 @@
-use leptos::*;
+use leptos::prelude::*;
pub mod header;
pub mod skeleton;
diff --git a/example/start-csr/src/components/skeleton.rs b/example/start-csr/src/components/skeleton.rs
index cd91db5..1817eb0 100644
--- a/example/start-csr/src/components/skeleton.rs
+++ b/example/start-csr/src/components/skeleton.rs
@@ -1,4 +1,4 @@
-use leptos::*;
+use leptos::prelude::*;
#[component]
pub fn Skeleton(#[prop(optional, into)] class: String) -> impl IntoView {
diff --git a/example/start-csr/src/components/spinner.rs b/example/start-csr/src/components/spinner.rs
index f918bdc..a1d8469 100644
--- a/example/start-csr/src/components/spinner.rs
+++ b/example/start-csr/src/components/spinner.rs
@@ -1,4 +1,4 @@
-use leptos::*;
+use leptos::prelude::*;
#[component]
pub fn Spinner(#[prop(into)] fetching: Signal) -> impl IntoView {
diff --git a/example/start-csr/src/components/switch.rs b/example/start-csr/src/components/switch.rs
index b0939bc..b96eeb2 100644
--- a/example/start-csr/src/components/switch.rs
+++ b/example/start-csr/src/components/switch.rs
@@ -1,4 +1,4 @@
-use leptos::*;
+use leptos::prelude::*;
#[component]
pub fn Switch(
diff --git a/example/start-csr/src/layout.rs b/example/start-csr/src/layout.rs
index 5004641..33b6bf7 100644
--- a/example/start-csr/src/layout.rs
+++ b/example/start-csr/src/layout.rs
@@ -1,6 +1,6 @@
use std::str::FromStr;
-use leptos::*;
+use leptos::prelude::*;
use leptos_meta::Html;
use leptos_query::query_persister::{IndexedDbPersister, LocalStoragePersister};
use leptos_query::use_query_client;
@@ -72,9 +72,9 @@ fn SelectPersister() -> impl IntoView {
let (persister, set_persister, _) =
use_local_storage::(Persister::None);
- create_effect(move |_| set_persister(persister.get_untracked()));
+ Effect::new(move |_| set_persister(persister.get_untracked()));
- create_effect(move |_| {
+ Effect::new(move |_| {
let client = use_query_client();
let persister = persister.get();
diff --git a/example/start-csr/src/lib.rs b/example/start-csr/src/lib.rs
index dc7450c..fb0dcdc 100644
--- a/example/start-csr/src/lib.rs
+++ b/example/start-csr/src/lib.rs
@@ -1,4 +1,4 @@
-use leptos::*;
+use leptos::prelude::*;
use leptos_meta::*;
use leptos_query::{provide_query_client_with_options, DefaultQueryOptions};
use leptos_query_devtools::LeptosQueryDevtools;
diff --git a/example/start-csr/src/main.rs b/example/start-csr/src/main.rs
index ee292bb..bb7433d 100644
--- a/example/start-csr/src/main.rs
+++ b/example/start-csr/src/main.rs
@@ -1,4 +1,4 @@
-use leptos::*;
+use leptos::prelude::*;
use start_csr::App;
fn main() {
diff --git a/example/start-csr/src/pages/home.rs b/example/start-csr/src/pages/home.rs
index 330720e..81cc35e 100644
--- a/example/start-csr/src/pages/home.rs
+++ b/example/start-csr/src/pages/home.rs
@@ -1,4 +1,4 @@
-use leptos::*;
+use leptos::prelude::*;
use crate::components::Loud;
diff --git a/example/start-csr/src/pages/interactive.rs b/example/start-csr/src/pages/interactive.rs
index 6ea7c38..2d56258 100644
--- a/example/start-csr/src/pages/interactive.rs
+++ b/example/start-csr/src/pages/interactive.rs
@@ -1,6 +1,6 @@
use std::{cell::RefCell, time::Duration};
-use leptos::*;
+use leptos::prelude::*;
use leptos_query::{create_query, QueryOptions, QueryScope};
use serde::{Deserialize, Serialize};
@@ -120,9 +120,9 @@ fn TodoListItem(todo: Todo) -> impl IntoView {
fn AddTodoEntry() -> impl IntoView {
let form_ref = create_node_ref::();
- let titleX = create_rw_signal("".to_string());
- let contentX = create_rw_signal("".to_string());
- let loading = create_rw_signal(false);
+ let titleX = RwSignal::new("".to_string());
+ let contentX = RwSignal::new("".to_string());
+ let loading = RwSignal::new(false);
let add_todo = move || {
let all_todos = all_todos_query();
diff --git a/example/start-csr/src/pages/intro.rs b/example/start-csr/src/pages/intro.rs
index 3a9133b..80bc7e2 100644
--- a/example/start-csr/src/pages/intro.rs
+++ b/example/start-csr/src/pages/intro.rs
@@ -1,4 +1,4 @@
-use leptos::*;
+use leptos::prelude::*;
#[component]
pub fn Introduction() -> impl IntoView {
diff --git a/example/start-csr/src/pages/not_found.rs b/example/start-csr/src/pages/not_found.rs
index 85774bb..600ae5d 100644
--- a/example/start-csr/src/pages/not_found.rs
+++ b/example/start-csr/src/pages/not_found.rs
@@ -1,4 +1,4 @@
-use leptos::*;
+use leptos::prelude::*;
/// 404 Not Found Page
#[component]
diff --git a/example/start-csr/src/pages/single.rs b/example/start-csr/src/pages/single.rs
index b8ff531..540c3c1 100644
--- a/example/start-csr/src/pages/single.rs
+++ b/example/start-csr/src/pages/single.rs
@@ -1,6 +1,6 @@
use std::time::Duration;
-use leptos::*;
+use leptos::prelude::*;
use leptos_query::{create_query, QueryOptions, QueryScope};
use serde::*;
@@ -21,7 +21,7 @@ pub fn QueryVsResource() -> impl IntoView {
#[component]
fn SingleQuery() -> impl IntoView {
- let post_id = create_rw_signal(1_u32);
+ let post_id = RwSignal::new(1_u32);
let query = post_query().use_query(move || PostQueryKey(post_id.get()));
@@ -138,7 +138,7 @@ const HEADER_CLASS: &str = "scroll-m-20 text-4xl font-bold tracking-tight";
#[component]
fn SingleResource() -> impl IntoView {
- let post_id = create_rw_signal(1_u32);
+ let post_id = RwSignal::new(1_u32);
let resource = create_local_resource(post_id, get_post);
diff --git a/query/Cargo.toml b/query/Cargo.toml
index c9cd7cc..c06ac90 100644
--- a/query/Cargo.toml
+++ b/query/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "leptos_query"
-version = "0.5.3"
+version = "0.6.0"
edition = "2021"
authors = ["Nico Burniske"]
description = "Async query manager for Leptos"
@@ -15,22 +15,22 @@ leptos = { workspace = true }
cfg-if = { workspace = true }
js-sys = { workspace = true, optional = true }
web-sys = { workspace = true, optional = true }
-miniserde = { version = "0.1", optional = true }
-gloo-timers = { workspace = true, optional = true }
tokio = { workspace = true, optional = true }
slotmap = { workspace = true }
futures-channel = { workspace = true }
futures = { workspace = true }
async-trait = { version = "0.1" }
-indexed_db_futures = { version = "0.4", optional = true }
+indexed_db_futures = { version = "0.5", optional = true }
async_cell = { version = "0.2.2", optional = true }
+serde = { workspace = true }
+serde_json = "1"
[features]
-hydrate = ["js-sys", "web-sys", "gloo-timers", "async_cell"]
-csr = ["js-sys", "web-sys", "gloo-timers", "async_cell"]
+hydrate = ["js-sys", "web-sys", "async_cell"]
+csr = ["js-sys", "web-sys", "async_cell"]
ssr = ["tokio"]
-local_storage = ["miniserde", "web-sys/Storage"]
-indexed_db = [ "miniserde", "indexed_db_futures"]
+local_storage = ["web-sys/Storage"]
+indexed_db = ["indexed_db_futures"]
[dev-dependencies]
leptos_axum = "0.6.5"
diff --git a/query/src/cache_observer.rs b/query/src/cache_observer.rs
index 9ecfe82..aaf5e88 100644
--- a/query/src/cache_observer.rs
+++ b/query/src/cache_observer.rs
@@ -1,4 +1,4 @@
-use std::{fmt::Debug, rc::Rc};
+use std::{fmt::Debug, sync::Arc};
use crate::{query::Query, QueryState};
@@ -49,13 +49,10 @@ impl CacheEvent {
CacheEvent::Removed(key.into())
}
- pub(crate) fn observer_added(key: &K, options: crate::QueryOptions) -> Self
+ pub(crate) fn observer_added(key: &K, options: crate::QueryOptions) -> Self
where
- K: crate::QueryKey + 'static,
- V: crate::QueryValue + 'static,
+ K: crate::QueryKey + 'static
{
- let options =
- options.map_value(|v| leptos::Serializable::ser(&v).expect("Serialize Query Options"));
CacheEvent::ObserverAdded(ObserverAdded {
key: key.into(),
options,
@@ -78,7 +75,7 @@ pub struct CreatedQuery {
/// Serialized query state.
pub state: QueryState,
/// Mark invalid
- pub mark_invalid: Rc bool>,
+ pub mark_invalid: Arc bool + Send + Sync>,
}
impl Debug for CreatedQuery {
@@ -109,7 +106,7 @@ pub struct ObserverAdded {
/// The key of the query.
pub key: QueryCacheKey,
/// The observers options.
- pub options: crate::QueryOptions,
+ pub options: crate::QueryOptions,
}
impl From> for CreatedQuery
@@ -120,10 +117,10 @@ where
fn from(query: Query) -> Self {
let key: QueryCacheKey = query.get_key().into();
let state = query.with_state(|state| {
- state.map_data(|data| leptos::Serializable::ser(data).expect("Serialize Query State"))
+ state.map_data(|data| serde_json::to_string(data).expect("Serialize Query State"))
});
- let mark_invalid = Rc::new(move || query.mark_invalid());
+ let mark_invalid = Arc::new(move || query.mark_invalid());
CreatedQuery {
key,
@@ -141,7 +138,7 @@ where
fn from(query: Query) -> Self {
let key: QueryCacheKey = query.get_key().into();
let state = query.with_state(|state| {
- state.map_data(|data| leptos::Serializable::ser(data).expect("Serialize Query State"))
+ state.map_data(|data| serde_json::to_string(data).expect("Serialize Query State"))
});
SerializedQuery { key, state }
diff --git a/query/src/create_query.rs b/query/src/create_query.rs
index 707a0cc..f42456c 100644
--- a/query/src/create_query.rs
+++ b/query/src/create_query.rs
@@ -1,8 +1,8 @@
use std::pin::Pin;
-use std::rc::Rc;
+use std::sync::Arc;
use std::{borrow::Borrow, future::Future};
-use leptos::Signal;
+use leptos::prelude::Signal;
use crate::{
use_query, use_query_client, QueryKey, QueryOptions, QueryResult, QueryState, QueryValue,
@@ -24,13 +24,13 @@ use crate::{
///
/// ```
/// use leptos_query::*;
-/// use leptos::*;
+/// use leptos::prelude::*;
///
/// #[component]
/// pub fn App() -> impl IntoView {
/// let scope = track_query();
/// let QueryResult { data, .. } = scope.use_query(|| TrackId(1));
-///
+///
/// view! {
///
/// // Query data should be read inside a Transition/Suspense component.
@@ -75,15 +75,15 @@ use crate::{
///
/// ```
pub fn create_query
(
- fetcher: impl Fn(K) -> Fu + 'static,
- options: QueryOptions,
+ fetcher: impl Fn(K) -> Fu + Send + Sync + 'static,
+ options: QueryOptions,
) -> QueryScope
where
K: QueryKey + 'static,
V: QueryValue + 'static,
- Fu: Future