Skip to content

Commit

Permalink
Merge pull request #19 from leptos-form/leptos-server-fn-tracing
Browse files Browse the repository at this point in the history
bump leptos to 0.6.0-beta
  • Loading branch information
tlowerison authored Jan 23, 2024
2 parents 785ea06 + 1463701 commit cb0e9fd
Show file tree
Hide file tree
Showing 12 changed files with 382 additions and 129 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-11-01
toolchain: stable
components: clippy,rustfmt

- uses: Swatinem/rust-cache@v2
Expand All @@ -42,17 +42,17 @@ jobs:

- run: pre-commit run --all-files --hook-stage push

- name: rust-grcov
uses: actions-rs/grcov@v0.1

- name: Codecov
uses: codecov/codecov-action@v4-beta
continue-on-error: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
# Repository upload token - get it from codecov.io. Required only for private repositories
# token: # optional
# Specify whether the Codecov output should be verbose
verbose: true
fail_ci_if_error: false
# - name: rust-grcov
# uses: actions-rs/grcov@v0.1

# - name: Codecov
# uses: codecov/codecov-action@v4-beta
# continue-on-error: true
# env:
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
# with:
# # Repository upload token - get it from codecov.io. Required only for private repositories
# # token: # optional
# # Specify whether the Codecov output should be verbose
# verbose: true
# fail_ci_if_error: false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
Cargo.lock
.DS_Store
rust-toolchain.toml
40 changes: 19 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ repos:
- --fix
- --allow-dirty
- --allow-staged
- --
- -D
- warnings
language: system
types: [file]
files: (\.rs|Cargo\.toml)$
Expand Down Expand Up @@ -108,33 +111,28 @@ repos:
types: [rust]
args: ["--"]

- id: cargo-doc
name: cargo-doc
description: ensure cargo doc builds
stages: [push]
entry: sh
args:
- -c
- "RUSTDOCFLAGS=\"-D warnings\" cargo doc --all-features"
language: system
types: [file]
files: (\.md|\.rs|Cargo\.toml)$
exclude: (CHANGELOG|DEVELOPMENT)\.md$
pass_filenames: false
# - id: cargo-doc
# name: cargo-doc
# description: ensure cargo doc builds
# stages: [push]
# entry: sh
# args:
# - -c
# - "RUSTDOCFLAGS=\"-D warnings\" cargo doc --all-features"
# language: system
# types: [file]
# files: (\.md|\.rs|Cargo\.toml)$
# exclude: (CHANGELOG|DEVELOPMENT)\.md$
# pass_filenames: false

- id: cargo-test
name: cargo-test
description: run all tests
stages: [push]
entry: sh
entry: cargo
args:
- -c
- |
CARGO_INCREMENTAL="0" \
RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests" \
RUSTDOCFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests" \
cargo test \
--all-features
- test
- --all-features
language: system
types: [file]
files: (\.md|\.rs|Cargo\.toml)$
Expand Down
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resolver = "2"

[workspace.package]
# update the internal crate versions when updating this workspace version
version = "0.1.8"
version = "0.2.0-beta"
edition = "2021"
rust-version = "1.75.0"
authors = ["Trey Lowerison <19714082+tlowerison@users.noreply.github.com>"]
Expand All @@ -15,9 +15,9 @@ keywords = ["leptos", "form", "derive-macros", "ui"]

[workspace.dependencies]
# internal to this workspace
leptos_form_core = { version = "=0.1.8", path = "core" }
leptos_form_proc_macros = { version = "=0.1.8", path = "proc_macros" }
leptos_form_proc_macros_core = { version = "=0.1.8", path = "proc_macros/core" }
leptos_form_core = { version = "=0.2.0-beta", path = "core" }
leptos_form_proc_macros = { version = "=0.2.0-beta", path = "proc_macros" }
leptos_form_proc_macros_core = { version = "=0.2.0-beta", path = "proc_macros/core" }

bigdecimal = "~0.4"
chrono = { version = "0", features = ["std"] }
Expand All @@ -29,8 +29,8 @@ indexmap = "2"
inner = "0"
itertools = "~0.12"
js-sys = "~0.3"
leptos = { version = "~0.5" }
leptos_router = "~0.5"
leptos = "0.6.0-beta"
leptos_router = "0.6.0-beta"
num-bigint = { version = "~0.4", default-features = false }
paste = "~1"
prettyplease = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion core/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl SerdeSerializer for SerdeJson {
}

#[cfg(feature = "cache-local-storage")]
impl<CS: CacheSerializer<T, Serialized = String>, T> Cache<CS, T> for LocalStorage<CS> {
impl<T, CS: CacheSerializer<T, Serialized = String>> Cache<CS, T> for LocalStorage<CS> {
type Error = CS::Error;
fn get_item(&self, key: &str) -> impl Future<Output = Result<Option<T>, CS::Error>> + Send {
use wasm_bindgen::UnwrapThrowExt;
Expand Down
16 changes: 2 additions & 14 deletions core/src/form_component/impls/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,8 @@ where
.collect::<IndexMap<_, _>>()
}))
}
fn is_initial_value(signal: &Self::Signal) -> bool {
signal.initial.with(|initial| {
signal.value.with(|value| match initial.as_ref() {
Some(initial) => {
let no_keys_changed = value.len() == initial.len()
&& value.last().map(|item| item.0) == initial.last().map(|item| item.0);
if !no_keys_changed {
return false;
}
value.iter().all(|(_, item)| T::is_initial_value(&item.signal))
}
None => value.is_empty(),
})
})
fn is_default_value(signal: &Self::Signal) -> bool {
signal.value.with(|value| value.is_empty())
}
fn into_signal(self, config: &Self::Config, initial: Option<Self>) -> Self::Signal {
let has_initial = initial.is_some();
Expand Down
49 changes: 27 additions & 22 deletions core/src/form_component/impls/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@ mod uuid {
fn default_signal(config: &Self::Config, initial: Option<Self>) -> Self::Signal {
FormFieldSignal::new_with_default_value(initial.map(|x| x.to_string()))
}
fn is_initial_value(signal: &Self::Signal) -> bool {
signal.value.with(|value| {
signal.initial.with(|initial| match initial {
Some(initial) => initial == value,
None => value.is_empty(),
})
})
fn is_default_value(signal: &Self::Signal) -> bool {
signal.value.with(|value| value.is_empty())
}
fn into_signal(self, _: &Self::Config, initial: Option<Self>) -> Self::Signal {
FormFieldSignal::new(self.to_string(), initial.map(|x| x.to_string()))
Expand Down Expand Up @@ -62,9 +57,13 @@ mod uuid {
name={props.name}
on:input=move |ev| props.signal.value.update(|value| *value = event_target_value(&ev))
on:change=move |_| {
if let Err(form_error) = <Self as FormField<HtmlElement<Input>>>::try_from_signal(props.signal, &props.config) {
props.signal.error.update(|error| *error = Some(form_error));
} else if props.signal.error.with_untracked(|error| error.is_some()) {
if !props.is_optional || !<Self as FormField<HtmlElement<Input>>>::is_default_value(&props.signal) {
if let Err(form_error) = <Self as FormField<HtmlElement<Input>>>::try_from_signal(props.signal, &props.config) {
props.signal.error.update(|error| *error = Some(form_error));
} else if props.signal.error.with_untracked(|error| error.is_some()) {
props.signal.error.update(|error| *error = None);
}
} else {
props.signal.error.update(|error| *error = None);
}
}
Expand All @@ -86,33 +85,38 @@ pub mod chrono {

#[derive(Clone, Debug)]
pub struct NaiveDateConfig {
/// defaults to `"%F"`
pub format: &'static str,
}
#[derive(Clone, Debug)]
pub struct NaiveDateTimeConfig {
/// defaults to `"%FT%T"`
pub format: &'static str,
}
#[derive(Clone, Debug)]
pub struct FixedOffsetDateTimeConfig {
/// defaults to `"%+"`
pub format: &'static str,
}
#[derive(Clone, Debug)]
pub struct UtcDateTimeConfig {
/// defaults to `"%+"`
pub format: &'static str,
}
#[derive(Clone, Debug)]
pub struct LocalDateTimeConfig {
/// defaults to `"%FT%T"`
pub format: &'static str,
}

impl Default for NaiveDateConfig {
fn default() -> Self {
Self { format: "%x" }
Self { format: "%F" }
}
}
impl Default for NaiveDateTimeConfig {
fn default() -> Self {
Self { format: "%c" }
Self { format: "%FT%T" }
}
}
impl Default for FixedOffsetDateTimeConfig {
Expand All @@ -122,12 +126,12 @@ pub mod chrono {
}
impl Default for UtcDateTimeConfig {
fn default() -> Self {
Self { format: "%c" }
Self { format: "%+" }
}
}
impl Default for LocalDateTimeConfig {
fn default() -> Self {
Self { format: "%c" }
Self { format: "%FT%T" }
}
}

Expand All @@ -148,11 +152,8 @@ pub mod chrono {
fn default_signal(config: &Self::Config, initial: Option<Self>) -> Self::Signal {
FormFieldSignal::new_with_default_value(initial.map(|x| x.format(config.format).to_string()))
}
fn is_initial_value(signal: &Self::Signal) -> bool {
signal.value.with(|value| signal.initial.with(|initial| match initial {
Some(initial) => initial == value,
None => value.is_empty(),
}))
fn is_default_value(signal: &Self::Signal) -> bool {
signal.value.with(|value| value.is_empty())
}
fn into_signal(self, config: &Self::Config, initial: Option<Self>) -> Self::Signal {
FormFieldSignal::new(self.format(config.format).to_string(), initial.map(|initial| initial.format(config.format).to_string()))
Expand Down Expand Up @@ -181,9 +182,13 @@ pub mod chrono {
name={props.name}
on:input=move |ev| props.signal.value.update(|value| *value = event_target_value(&ev))
on:change=move |_| {
if let Err(form_error) = <Self as FormField<HtmlElement<Input>>>::try_from_signal(props.signal, &props.config) {
props.signal.error.update(|error| *error = Some(form_error));
} else if props.signal.error.with_untracked(|error| error.is_some()) {
if !props.is_optional || !Self::is_default_value(&props.signal) {
if let Err(form_error) = <Self as FormField<HtmlElement<Input>>>::try_from_signal(props.signal, &props.config) {
props.signal.error.update(|error| *error = Some(form_error));
} else if props.signal.error.with_untracked(|error| error.is_some()) {
props.signal.error.update(|error| *error = None);
}
} else {
props.signal.error.update(|error| *error = None);
}
}
Expand Down
17 changes: 9 additions & 8 deletions core/src/form_component/impls/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ macro_rules! num_impl {
fn default_signal(_: &Self::Config, initial: Option<Self>) -> Self::Signal {
FormFieldSignal::new_with_default_value(initial.map(|x| x.to_string()))
}
fn is_initial_value(signal: &Self::Signal) -> bool {
signal.value.with(|value| signal.initial.with(|initial| match initial {
Some(initial) => initial == value,
None => value.is_empty(),
}))
fn is_default_value(signal: &Self::Signal) -> bool {
signal.value.with(|value| value.is_empty())
}
fn into_signal(self, _: &Self::Config, initial: Option<Self>) -> Self::Signal {
FormFieldSignal::new(self.to_string(), initial.map(|x| x.to_string()))
Expand Down Expand Up @@ -53,9 +50,13 @@ macro_rules! num_impl {
on:keydown=num_impl!(@prevent_invalid_keystrokes value $($($type)?)?)
on:input=move |ev| props.signal.value.update(|value| *value = event_target_value(&ev))
on:change=move |_| {
if let Err(form_error) = <Self as FormField<HtmlElement<Input>>>::try_from_signal(props.signal, &props.config) {
props.signal.error.update(|error| *error = Some(form_error));
} else if props.signal.error.with_untracked(|error| error.is_some()) {
if !props.is_optional || !<Self as FormField<HtmlElement<Input>>>::is_default_value(&props.signal) {
if let Err(form_error) = <Self as FormField<HtmlElement<Input>>>::try_from_signal(props.signal, &props.config) {
props.signal.error.update(|error| *error = Some(form_error));
} else if props.signal.error.with_untracked(|error| error.is_some()) {
props.signal.error.update(|error| *error = None);
}
} else {
props.signal.error.update(|error| *error = None);
}
}
Expand Down
19 changes: 9 additions & 10 deletions core/src/form_component/impls/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@ macro_rules! str_impl {
fn default_signal(_: &Self::Config, initial: Option<Self>) -> Self::Signal {
FormFieldSignal::new_with_default_value(initial.map(|x| x.to_string()))
}
fn is_initial_value(signal: &Self::Signal) -> bool {
signal.value.with(|value| signal.initial.with(|initial| {
match initial {
Some(initial) => initial == value,
None => value.is_empty(),
}
}))
fn is_default_value(signal: &Self::Signal) -> bool {
signal.value.with(|value| value.is_empty())
}
fn into_signal(self, _: &Self::Config, initial: Option<Self>) -> Self::Signal {
FormFieldSignal::new(self.to_string(), initial.map(|x| x.to_string()))
Expand Down Expand Up @@ -58,9 +53,13 @@ macro_rules! str_impl {
name={props.name}
on:input=move |ev| props.signal.value.update(|value| *value = event_target_value(&ev))
on:change=move |_| {
if let Err(form_error) = <Self as FormField<HtmlElement<Input>>>::try_from_signal(props.signal, &props.config) {
props.signal.error.update(|error| *error = Some(form_error));
} else if props.signal.error.with_untracked(|error| error.is_some()) {
if !props.is_optional || !<Self as FormField<HtmlElement<$el>>>::is_default_value(&props.signal) {
if let Err(form_error) = <Self as FormField<HtmlElement<Input>>>::try_from_signal(props.signal, &props.config) {
props.signal.error.update(|error| *error = Some(form_error));
} else if props.signal.error.with_untracked(|error| error.is_some()) {
props.signal.error.update(|error| *error = None);
}
} else {
props.signal.error.update(|error| *error = None);
}
}
Expand Down
Loading

0 comments on commit cb0e9fd

Please sign in to comment.