Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ package.repository = "https://github.com/DioxusLabs/sdk/"

[workspace.dependencies]
# Workspace
dioxus-sdk = { path = "packages/sdk", version = "0.7.0-alpha.1" }
dioxus-time = { path = "packages/time", version = "0.1.0-alpha.1" }
dioxus_storage = { path = "packages/storage", version = "0.1.0-alpha.1" }
dioxus-geolocation = { path = "packages/geolocation", version = "0.1.0-alpha.1" }
dioxus-notification = { path = "packages/notification", version = "0.1.0-alpha.1" }
dioxus-sync = { path = "packages/sync", version = "0.1.0-alpha.1" }
dioxus-util = { path = "packages/util", version = "0.1.0-alpha.1" }
dioxus-window = { path = "packages/window", version = "0.1.0-alpha.1" }
dioxus-sdk = { path = "packages/sdk", version = "0.7.0-rc.1" }
dioxus-time = { path = "packages/time", version = "0.7.0-rc.1" }
dioxus_storage = { path = "packages/storage", version = "0.7.0-rc.1" }
dioxus-geolocation = { path = "packages/geolocation", version = "0.7.0-rc.1" }
dioxus-notification = { path = "packages/notification", version = "0.7.0-rc.1" }
dioxus-sync = { path = "packages/sync", version = "0.7.0-rc.1" }
dioxus-util = { path = "packages/util", version = "0.7.0-rc.1" }
dioxus-window = { path = "packages/window", version = "0.7.0-rc.1" }

# Dioxus
dioxus = "0.6.0"
dioxus-signals = "0.6.0"
dioxus-desktop = "0.6.0"
dioxus-config-macro = "0.6.0"
dioxus = "^0.7.0-rc.1"
dioxus-signals = "^0.7.0-rc.1"
dioxus-desktop = "^0.7.0-rc.1"
dioxus-config-macro = "^0.7.0-rc.1"

# Deps
cfg-if = "1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/geolocation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dioxus-geolocation"
version = "0.1.0-alpha.1"
version = "0.7.0-rc.1"

description = "Geolocation utilities and hooks for Dioxus."
readme = "./README.md"
Expand Down
8 changes: 4 additions & 4 deletions packages/geolocation/src/use_geolocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use super::core::{Error, Event, Geocoordinates, Geolocator, PowerMode, Status};
use dioxus::{
prelude::{
ReadOnlySignal, Signal, UnboundedReceiver, provide_context, try_consume_context,
use_coroutine, use_hook, use_signal,
ReadSignal, Signal, UnboundedReceiver, provide_context, try_consume_context, use_coroutine,
use_hook, use_signal,
},
signals::{Readable, Writable},
};
Expand All @@ -14,7 +14,7 @@ use std::sync::Once;
static INIT: Once = Once::new();

/// Provides the latest geocoordinates. Good for navigation-type apps.
pub fn use_geolocation() -> ReadOnlySignal<Result<Geocoordinates, Error>> {
pub fn use_geolocation() -> ReadSignal<Result<Geocoordinates, Error>> {
// Store the coords
let mut coords: Signal<Result<Geocoordinates, Error>> =
use_signal(|| Err(Error::NotInitialized));
Expand Down Expand Up @@ -52,7 +52,7 @@ pub fn use_geolocation() -> ReadOnlySignal<Result<Geocoordinates, Error>> {
}
}

use_hook(|| ReadOnlySignal::new(coords))
use_hook(|| ReadSignal::new(coords))
}

/// Must be called before any use of the geolocation abstraction.
Expand Down
2 changes: 1 addition & 1 deletion packages/notification/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dioxus-notification"
version = "0.1.0-alpha.1"
version = "0.7.0-rc.1"

description = "Send notifications from your Dioxus apps."
readme = "./README.md"
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dioxus-sdk"
version = "0.7.0-alpha.1"
version = "0.7.0-rc.1"

description = "A platform agnostic library for supercharging your productivity with Dioxus."
readme = "../../README.md"
Expand Down Expand Up @@ -32,4 +32,4 @@ util = ["dep:dioxus-util"]
window = ["dep:dioxus-window"]

[package.metadata.docs.rs]
all-features = true
all-features = true
2 changes: 1 addition & 1 deletion packages/storage/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dioxus_storage"
version = "0.1.0-alpha.1"
version = "0.7.0-rc.1"

description = "Local and persistent storage utilities for Dioxus."
readme = "./README.md"
Expand Down
19 changes: 10 additions & 9 deletions packages/storage/src/client_storage/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::ops::{Deref, DerefMut};
use std::rc::Rc;
use std::sync::Arc;

use dioxus::core::{consume_context_from_scope, provide_root_context};

use crate::StorageBacking;

#[derive(Clone)]
Expand Down Expand Up @@ -42,15 +44,14 @@ impl SessionStore {

/// Get the current session store from the root context, or create a new one if it doesn't exist.
fn get_current_session() -> Self {
dioxus::prelude::consume_context_from_scope::<Self>(dioxus::prelude::ScopeId::ROOT)
.map_or_else(
|| {
let session = Self::new();
dioxus::prelude::provide_root_context(session.clone());
session
},
|s| s,
)
consume_context_from_scope::<Self>(dioxus::prelude::ScopeId::ROOT).map_or_else(
|| {
let session = Self::new();
provide_root_context(session.clone());
session
},
|s| s,
)
}
}

Expand Down
6 changes: 2 additions & 4 deletions packages/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mod client_storage;
mod persistence;

pub use client_storage::{LocalStorage, SessionStorage};
use dioxus::core::{ReactiveContext, current_scope_id, generation, needs_update};
use dioxus::logger::tracing::trace;
use futures_util::stream::StreamExt;
pub use persistence::{
Expand Down Expand Up @@ -401,10 +402,7 @@ where
pub fn new(key: S::Key, data: T) -> Self {
Self {
key,
data: Signal::new_in_scope(
data,
current_scope_id().expect("must be called from inside of the dioxus context"),
),
data: Signal::new_in_scope(data, current_scope_id()),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sync/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dioxus-sync"
version = "0.1.0-alpha.1"
version = "0.7.0-rc.1"

description = "Synchronization primitives for your Dioxus app."
readme = "./README.md"
Expand Down
4 changes: 2 additions & 2 deletions packages/time/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dioxus-time"
version = "0.1.0-alpha.1"
version = "0.7.0-rc.1"

description = "Timing utilities and hooks for Dioxus."
readme = "./README.md"
Expand All @@ -21,4 +21,4 @@ futures = { workspace = true }
tokio = { workspace = true, features = ["time"]}

[target.'cfg(target_family = "wasm")'.dependencies]
gloo-timers = { version = "0.3.0", features = ["futures"] }
gloo-timers = { version = "0.3.0", features = ["futures"] }
12 changes: 4 additions & 8 deletions packages/time/src/debounce.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use crate::{TimeoutHandle, UseTimeout, use_timeout};
use dioxus::{
dioxus_core::SpawnIfAsync,
hooks::use_signal,
signals::{Signal, Writable},
};
use dioxus::{dioxus_core::SpawnIfAsync, hooks::use_signal, prelude::WritableExt, signals::Signal};
use std::time::Duration;

/// The interface for calling a debounce.
Expand Down Expand Up @@ -48,7 +44,7 @@ impl<Args> UseDebounce<Args> {
/// // Create a two second debounce.
/// // This will print "ran" after two seconds since the last action call.
/// let mut debounce = use_debounce(Duration::from_secs(2), |_| println!("ran"));
///
///
/// rsx! {
/// button {
/// onclick: move |_| {
Expand All @@ -71,7 +67,7 @@ impl<Args> UseDebounce<Args> {
/// #[component]
/// fn App() -> Element {
/// let mut debounce = use_debounce(Duration::from_secs(5), |_| println!("ran"));
///
///
/// rsx! {
/// button {
/// // Start the debounce on click.
Expand Down Expand Up @@ -102,7 +98,7 @@ impl<Args> UseDebounce<Args> {
/// tokio::time::sleep(Duration::from_secs(2)).await;
/// println!("after async");
/// });
///
///
/// rsx! {
/// button {
/// onclick: move |_| {
Expand Down
9 changes: 5 additions & 4 deletions packages/time/src/interval.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use dioxus::{
core::Task,
dioxus_core::SpawnIfAsync,
prelude::{Callback, Task, Writable, spawn, use_hook},
prelude::{Callback, WritableExt, spawn, use_hook},
signals::Signal,
};
use std::time::Duration;
Expand Down Expand Up @@ -52,7 +53,7 @@ impl UseInterval {
/// let mut time_elapsed = use_signal(|| 0);
/// // Create an interval that increases the time elapsed signal by one every second.
/// use_interval(Duration::from_secs(1), move |()| time_elapsed += 1);
///
///
/// rsx! {
/// "It has been {time_elapsed} since the app started."
/// }
Expand All @@ -70,7 +71,7 @@ impl UseInterval {
/// fn App() -> Element {
/// let mut time_elapsed = use_signal(|| 0);
/// let mut interval = use_interval(Duration::from_secs(1), move |()| time_elapsed += 1);
///
///
/// rsx! {
/// "It has been {time_elapsed} since the app started."
/// button {
Expand Down Expand Up @@ -99,7 +100,7 @@ impl UseInterval {
/// tokio::time::sleep(Duration::from_secs(1)).await;
/// println!("Done!");
/// });
///
///
/// rsx! {
/// "It has been {time_elapsed} since the app started."
/// }
Expand Down
3 changes: 2 additions & 1 deletion packages/time/src/timeout.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use dioxus::{
core::Task,
dioxus_core::SpawnIfAsync,
prelude::{Callback, Task, spawn, use_hook},
prelude::{Callback, spawn, use_hook},
signals::Signal,
};
use futures::{SinkExt, StreamExt, channel::mpsc};
Expand Down
2 changes: 1 addition & 1 deletion packages/util/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dioxus-util"
version = "0.1.0-alpha.1"
version = "0.7.0-rc.1"

description = "General utilities for Dioxus apps."
readme = "./README.md"
Expand Down
2 changes: 1 addition & 1 deletion packages/util/src/scroll.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dioxus::prelude::*;
use dioxus::{core::use_drop, prelude::*};
use std::sync::atomic::{AtomicUsize, Ordering};

/// Scroll metrics.
Expand Down
2 changes: 1 addition & 1 deletion packages/window/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dioxus-window"
version = "0.1.0-alpha.1"
version = "0.7.0-rc.1"

description = "Window utilities and hooks for Dioxus."
readme = "./README.md"
Expand Down
31 changes: 13 additions & 18 deletions packages/window/src/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@
//!
//! fn App() -> Element {
//! let size = use_window_size();
//! let size = size().unwrap();
//! let size = size().unwrap();
//!
//! rsx! {
//! p { "Width: {size.width}" }
//! p { "Height: {size.height}" }
//! }
//! }
//! ```
use dioxus::core::provide_root_context;
use dioxus::hooks::use_effect;
use dioxus::prelude::{
ReadOnlySignal, ScopeId, Signal, Writable, provide_root_context, try_use_context, use_hook,
warnings::signal_write_in_component_body,
ReadSignal, ReadableExt, ScopeId, Signal, WritableExt, try_use_context, use_hook,
};
use dioxus::signals::Readable;
use dioxus::warnings::Warning as _;
use std::error::Error;
use std::fmt::Display;

Expand Down Expand Up @@ -75,7 +74,7 @@ type WindowSizeResult = Result<WindowSize, WindowSizeError>;
///
/// fn App() -> Element {
/// let size = use_window_size();
///
///
/// let half_of_width = use_memo(move || {
/// let width = size.width().unwrap();
/// width / 2
Expand Down Expand Up @@ -120,15 +119,15 @@ impl<R> ReadableWindowSizeExt for R where R: Readable<Target = WindowSizeResult>
///
/// fn App() -> Element {
/// let size = use_window_size();
/// let size = size().unwrap();
/// let size = size().unwrap();
///
/// rsx! {
/// p { "Width: {size.width}" }
/// p { "Height: {size.height}" }
/// }
/// }
/// ```
pub fn use_window_size() -> ReadOnlySignal<WindowSizeResult> {
pub fn use_window_size() -> ReadSignal<WindowSizeResult> {
let mut window_size = match try_use_context::<Signal<WindowSizeResult>>() {
Some(w) => w,
// This should only run once.
Expand All @@ -144,7 +143,7 @@ pub fn use_window_size() -> ReadOnlySignal<WindowSizeResult> {
listen(window_size);
});

use_hook(|| ReadOnlySignal::new(window_size))
use_hook(|| ReadSignal::new(window_size))
}

// Listener for the web implementation.
Expand Down Expand Up @@ -177,9 +176,7 @@ fn listen(mut window_size: Signal<WindowSizeResult>) {
_ => Err(WindowSizeError::CheckFailed),
};

signal_write_in_component_body::allow(move || {
window_size.set(value);
});
window_size.set(value);
}) as Box<dyn FnMut()>);

let on_resize_cb = on_resize.as_ref().clone();
Expand All @@ -199,12 +196,10 @@ fn listen(mut window_size: Signal<WindowSizeResult>) {
..
} = event
{
signal_write_in_component_body::allow(move || {
window_size.set(Ok(WindowSize {
width: size.width,
height: size.height,
}));
});
window_size.set(Ok(WindowSize {
width: size.width,
height: size.height,
}));
}
});
}
Expand All @@ -223,7 +218,7 @@ fn listen(mut window_size: Signal<WindowSizeResult>) {
///
/// fn App() -> Element {
/// let size = use_signal(get_window_size);
/// let size = size().unwrap();
/// let size = size().unwrap();
///
/// rsx! {
/// p { "Width: {size.width}" }
Expand Down
Loading