Compare commits

..

1 Commits
v0.5.1 ... 1754

Author SHA1 Message Date
Greg Johnston
891448d0fa fix: router animations should reset to Start state (closes #1754) 2023-09-30 16:32:35 -04:00
43 changed files with 192 additions and 840 deletions

View File

@@ -20,7 +20,7 @@ jobs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v3
with:
fetch-depth: 0

View File

@@ -15,7 +15,7 @@ jobs:
example_changed: ${{ steps.set-example-changed.outputs.example_changed }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v3
with:
fetch-depth: 0

View File

@@ -15,7 +15,7 @@ jobs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v3
- name: Install JQ Tool
uses: mbround18/install-jq@v1
@@ -23,12 +23,12 @@ jobs:
- name: Set Matrix
id: set-matrix
run: |
examples=$(ls examples |
awk '{print "examples/" $0}' |
grep -v .md |
grep -v examples/Makefile.toml |
grep -v examples/cargo-make |
grep -v examples/gtk |
examples=$(ls examples |
awk '{print "examples/" $0}' |
grep -v .md |
grep -v examples/Makefile.toml |
grep -v examples/cargo-make |
grep -v examples/gtk |
jq -R -s -c 'split("\n")[:-1]')
echo "Example Directories: $examples"
echo "matrix={\"directory\":$examples}" >> "$GITHUB_OUTPUT"

View File

@@ -15,7 +15,7 @@ jobs:
leptos_changed: ${{ steps.set-source-changed.outputs.leptos_changed }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v3
- name: Get source files that changed
id: changed-source

View File

@@ -12,7 +12,7 @@ jobs:
contents: write # To push a branch
pull-requests: write # To create a PR from that branch
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install mdbook

View File

@@ -26,22 +26,22 @@ members = [
exclude = ["benchmarks", "examples"]
[workspace.package]
version = "0.5.1"
version = "0.5.0"
[workspace.dependencies]
leptos = { path = "./leptos", version = "0.5.1" }
leptos_dom = { path = "./leptos_dom", version = "0.5.1" }
leptos_hot_reload = { path = "./leptos_hot_reload", version = "0.5.1" }
leptos_macro = { path = "./leptos_macro", version = "0.5.1" }
leptos_reactive = { path = "./leptos_reactive", version = "0.5.1" }
leptos_server = { path = "./leptos_server", version = "0.5.1" }
server_fn = { path = "./server_fn", version = "0.5.1" }
server_fn_macro = { path = "./server_fn_macro", version = "0.5.1" }
server_fn_macro_default = { path = "./server_fn/server_fn_macro_default", version = "0.5.1" }
leptos_config = { path = "./leptos_config", version = "0.5.1" }
leptos_router = { path = "./router", version = "0.5.1" }
leptos_meta = { path = "./meta", version = "0.5.1" }
leptos_integration_utils = { path = "./integrations/utils", version = "0.5.1" }
leptos = { path = "./leptos", version = "0.5.0" }
leptos_dom = { path = "./leptos_dom", version = "0.5.0" }
leptos_hot_reload = { path = "./leptos_hot_reload", version = "0.5.0" }
leptos_macro = { path = "./leptos_macro", version = "0.5.0" }
leptos_reactive = { path = "./leptos_reactive", version = "0.5.0" }
leptos_server = { path = "./leptos_server", version = "0.5.0" }
server_fn = { path = "./server_fn", version = "0.5.0" }
server_fn_macro = { path = "./server_fn_macro", version = "0.5.0" }
server_fn_macro_default = { path = "./server_fn/server_fn_macro_default", version = "0.5.0" }
leptos_config = { path = "./leptos_config", version = "0.5.0" }
leptos_router = { path = "./router", version = "0.5.0" }
leptos_meta = { path = "./meta", version = "0.5.0" }
leptos_integration_utils = { path = "./integrations/utils", version = "0.5.0" }
[profile.release]
codegen-units = 1

View File

@@ -48,7 +48,7 @@ pub fn main() {
### Important Note
This example, and the entire `main` branch, now reflect the upcoming `0.5.1` release. You can use `0.5.1` with the `0.5.1-beta` release on crates.io or by a git dependency on the `main` branch of this repo. [Click here for the 0.4.9 `README`](https://crates.io/crates/leptos).
This example, and the entire `main` branch, now reflect the upcoming `0.5.0` release. You can use `0.5.0` with the `0.5.0-beta` release on crates.io or by a git dependency on the `main` branch of this repo. [Click here for the 0.4.9 `README`](https://crates.io/crates/leptos).
## About the Framework

View File

@@ -1,10 +1,2 @@
[output.html]
additional-css = ["./mdbook-admonish.css"]
[output.html.playground]
runnable = false
[preprocessor]
[preprocessor.admonish]
command = "mdbook-admonish"
assets_version = "2.0.2" # do not edit: managed by `mdbook-admonish install`

View File

@@ -1,353 +0,0 @@
@charset "UTF-8";
:root {
--md-admonition-icon--note:
url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83 3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75L3 17.25z'/></svg>");
--md-admonition-icon--abstract:
url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M17 9H7V7h10m0 6H7v-2h10m-3 6H7v-2h7M12 3a1 1 0 0 1 1 1 1 1 0 0 1-1 1 1 1 0 0 1-1-1 1 1 0 0 1 1-1m7 0h-4.18C14.4 1.84 13.3 1 12 1c-1.3 0-2.4.84-2.82 2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2z'/></svg>");
--md-admonition-icon--info:
url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M13 9h-2V7h2m0 10h-2v-6h2m-1-9A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10A10 10 0 0 0 12 2z'/></svg>");
--md-admonition-icon--tip:
url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M17.66 11.2c-.23-.3-.51-.56-.77-.82-.67-.6-1.43-1.03-2.07-1.66C13.33 7.26 13 4.85 13.95 3c-.95.23-1.78.75-2.49 1.32-2.59 2.08-3.61 5.75-2.39 8.9.04.1.08.2.08.33 0 .22-.15.42-.35.5-.23.1-.47.04-.66-.12a.58.58 0 0 1-.14-.17c-1.13-1.43-1.31-3.48-.55-5.12C5.78 10 4.87 12.3 5 14.47c.06.5.12 1 .29 1.5.14.6.41 1.2.71 1.73 1.08 1.73 2.95 2.97 4.96 3.22 2.14.27 4.43-.12 6.07-1.6 1.83-1.66 2.47-4.32 1.53-6.6l-.13-.26c-.21-.46-.77-1.26-.77-1.26m-3.16 6.3c-.28.24-.74.5-1.1.6-1.12.4-2.24-.16-2.9-.82 1.19-.28 1.9-1.16 2.11-2.05.17-.8-.15-1.46-.28-2.23-.12-.74-.1-1.37.17-2.06.19.38.39.76.63 1.06.77 1 1.98 1.44 2.24 2.8.04.14.06.28.06.43.03.82-.33 1.72-.93 2.27z'/></svg>");
--md-admonition-icon--success:
url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='m9 20.42-6.21-6.21 2.83-2.83L9 14.77l9.88-9.89 2.83 2.83L9 20.42z'/></svg>");
--md-admonition-icon--question:
url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='m15.07 11.25-.9.92C13.45 12.89 13 13.5 13 15h-2v-.5c0-1.11.45-2.11 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41a2 2 0 0 0-2-2 2 2 0 0 0-2 2H8a4 4 0 0 1 4-4 4 4 0 0 1 4 4 3.2 3.2 0 0 1-.93 2.25M13 19h-2v-2h2M12 2A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10c0-5.53-4.5-10-10-10z'/></svg>");
--md-admonition-icon--warning:
url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M13 14h-2V9h2m0 9h-2v-2h2M1 21h22L12 2 1 21z'/></svg>");
--md-admonition-icon--failure:
url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M20 6.91 17.09 4 12 9.09 6.91 4 4 6.91 9.09 12 4 17.09 6.91 20 12 14.91 17.09 20 20 17.09 14.91 12 20 6.91z'/></svg>");
--md-admonition-icon--danger:
url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M11 15H6l7-14v8h5l-7 14v-8z'/></svg>");
--md-admonition-icon--bug:
url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M14 12h-4v-2h4m0 6h-4v-2h4m6-6h-2.81a5.985 5.985 0 0 0-1.82-1.96L17 4.41 15.59 3l-2.17 2.17a6.002 6.002 0 0 0-2.83 0L8.41 3 7 4.41l1.62 1.63C7.88 6.55 7.26 7.22 6.81 8H4v2h2.09c-.05.33-.09.66-.09 1v1H4v2h2v1c0 .34.04.67.09 1H4v2h2.81c1.04 1.79 2.97 3 5.19 3s4.15-1.21 5.19-3H20v-2h-2.09c.05-.33.09-.66.09-1v-1h2v-2h-2v-1c0-.34-.04-.67-.09-1H20V8z'/></svg>");
--md-admonition-icon--example:
url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M7 13v-2h14v2H7m0 6v-2h14v2H7M7 7V5h14v2H7M3 8V5H2V4h2v4H3m-1 9v-1h3v4H2v-1h2v-.5H3v-1h1V17H2m2.25-7a.75.75 0 0 1 .75.75c0 .2-.08.39-.21.52L3.12 13H5v1H2v-.92L4 11H2v-1h2.25z'/></svg>");
--md-admonition-icon--quote:
url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M14 17h3l2-4V7h-6v6h3M6 17h3l2-4V7H5v6h3l-2 4z'/></svg>");
--md-details-icon:
url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M8.59 16.58 13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.42Z'/></svg>");
}
:is(.admonition) {
display: flow-root;
margin: 1.5625em 0;
padding: 0 1.2rem;
color: var(--fg);
page-break-inside: avoid;
background-color: var(--bg);
border: 0 solid black;
border-inline-start-width: 0.4rem;
border-radius: 0.2rem;
box-shadow: 0 0.2rem 1rem rgba(0, 0, 0, 0.05), 0 0 0.1rem rgba(0, 0, 0, 0.1);
}
@media print {
:is(.admonition) {
box-shadow: none;
}
}
:is(.admonition) > * {
box-sizing: border-box;
}
:is(.admonition) :is(.admonition) {
margin-top: 1em;
margin-bottom: 1em;
}
:is(.admonition) > .tabbed-set:only-child {
margin-top: 0;
}
html :is(.admonition) > :last-child {
margin-bottom: 1.2rem;
}
a.admonition-anchor-link {
display: none;
position: absolute;
left: -1.2rem;
padding-right: 1rem;
}
a.admonition-anchor-link:link, a.admonition-anchor-link:visited {
color: var(--fg);
}
a.admonition-anchor-link:link:hover, a.admonition-anchor-link:visited:hover {
text-decoration: none;
}
a.admonition-anchor-link::before {
content: "§";
}
:is(.admonition-title, summary.admonition-title) {
position: relative;
min-height: 4rem;
margin-block: 0;
margin-inline: -1.6rem -1.2rem;
padding-block: 0.8rem;
padding-inline: 4.4rem 1.2rem;
font-weight: 700;
background-color: rgba(68, 138, 255, 0.1);
display: flex;
}
:is(.admonition-title, summary.admonition-title) p {
margin: 0;
}
html :is(.admonition-title, summary.admonition-title):last-child {
margin-bottom: 0;
}
:is(.admonition-title, summary.admonition-title)::before {
position: absolute;
top: 0.625em;
inset-inline-start: 1.6rem;
width: 2rem;
height: 2rem;
background-color: #448aff;
mask-image: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"></svg>');
-webkit-mask-image: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"></svg>');
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-size: contain;
content: "";
}
:is(.admonition-title, summary.admonition-title):hover a.admonition-anchor-link {
display: initial;
}
details.admonition > summary.admonition-title::after {
position: absolute;
top: 0.625em;
inset-inline-end: 1.6rem;
height: 2rem;
width: 2rem;
background-color: currentcolor;
mask-image: var(--md-details-icon);
-webkit-mask-image: var(--md-details-icon);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-size: contain;
content: "";
transform: rotate(0deg);
transition: transform 0.25s;
}
details[open].admonition > summary.admonition-title::after {
transform: rotate(90deg);
}
:is(.admonition):is(.note) {
border-color: #448aff;
}
:is(.note) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(68, 138, 255, 0.1);
}
:is(.note) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #448aff;
mask-image: var(--md-admonition-icon--note);
-webkit-mask-image: var(--md-admonition-icon--note);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.abstract, .summary, .tldr) {
border-color: #00b0ff;
}
:is(.abstract, .summary, .tldr) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(0, 176, 255, 0.1);
}
:is(.abstract, .summary, .tldr) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #00b0ff;
mask-image: var(--md-admonition-icon--abstract);
-webkit-mask-image: var(--md-admonition-icon--abstract);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.info, .todo) {
border-color: #00b8d4;
}
:is(.info, .todo) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(0, 184, 212, 0.1);
}
:is(.info, .todo) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #00b8d4;
mask-image: var(--md-admonition-icon--info);
-webkit-mask-image: var(--md-admonition-icon--info);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.tip, .hint, .important) {
border-color: #00bfa5;
}
:is(.tip, .hint, .important) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(0, 191, 165, 0.1);
}
:is(.tip, .hint, .important) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #00bfa5;
mask-image: var(--md-admonition-icon--tip);
-webkit-mask-image: var(--md-admonition-icon--tip);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.success, .check, .done) {
border-color: #00c853;
}
:is(.success, .check, .done) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(0, 200, 83, 0.1);
}
:is(.success, .check, .done) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #00c853;
mask-image: var(--md-admonition-icon--success);
-webkit-mask-image: var(--md-admonition-icon--success);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.question, .help, .faq) {
border-color: #64dd17;
}
:is(.question, .help, .faq) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(100, 221, 23, 0.1);
}
:is(.question, .help, .faq) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #64dd17;
mask-image: var(--md-admonition-icon--question);
-webkit-mask-image: var(--md-admonition-icon--question);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.warning, .caution, .attention) {
border-color: #ff9100;
}
:is(.warning, .caution, .attention) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(255, 145, 0, 0.1);
}
:is(.warning, .caution, .attention) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #ff9100;
mask-image: var(--md-admonition-icon--warning);
-webkit-mask-image: var(--md-admonition-icon--warning);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.failure, .fail, .missing) {
border-color: #ff5252;
}
:is(.failure, .fail, .missing) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(255, 82, 82, 0.1);
}
:is(.failure, .fail, .missing) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #ff5252;
mask-image: var(--md-admonition-icon--failure);
-webkit-mask-image: var(--md-admonition-icon--failure);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.danger, .error) {
border-color: #ff1744;
}
:is(.danger, .error) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(255, 23, 68, 0.1);
}
:is(.danger, .error) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #ff1744;
mask-image: var(--md-admonition-icon--danger);
-webkit-mask-image: var(--md-admonition-icon--danger);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.bug) {
border-color: #f50057;
}
:is(.bug) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(245, 0, 87, 0.1);
}
:is(.bug) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #f50057;
mask-image: var(--md-admonition-icon--bug);
-webkit-mask-image: var(--md-admonition-icon--bug);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.example) {
border-color: #7c4dff;
}
:is(.example) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(124, 77, 255, 0.1);
}
:is(.example) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #7c4dff;
mask-image: var(--md-admonition-icon--example);
-webkit-mask-image: var(--md-admonition-icon--example);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
:is(.admonition):is(.quote, .cite) {
border-color: #9e9e9e;
}
:is(.quote, .cite) > :is(.admonition-title, summary.admonition-title) {
background-color: rgba(158, 158, 158, 0.1);
}
:is(.quote, .cite) > :is(.admonition-title, summary.admonition-title)::before {
background-color: #9e9e9e;
mask-image: var(--md-admonition-icon--quote);
-webkit-mask-image: var(--md-admonition-icon--quote);
mask-repeat: no-repeat;
-webkit-mask-repeat: no-repeat;
mask-size: contain;
-webkit-mask-repeat: no-repeat;
}
.navy :is(.admonition) {
background-color: var(--sidebar-bg);
}
.ayu :is(.admonition), .coal :is(.admonition) {
background-color: var(--theme-hover);
}
.rust :is(.admonition) {
background-color: var(--sidebar-bg);
color: var(--sidebar-fg);
}
.rust .admonition-anchor-link:link, .rust .admonition-anchor-link:visited {
color: var(--sidebar-fg);
}

View File

@@ -17,6 +17,6 @@ understand Leptos.
You can find more detailed docs for each part of the API at [Docs.rs](https://docs.rs/leptos/latest/leptos/).
**Important Note**: This current version of the book reflects the `0.5.1` release. The CodeSandbox versions of the examples still reflect `0.4` and earlier APIs and are in the process of being updated.
**Important Note**: This current version of the book reflects the upcoming `0.5.0` release, which you can install as version `0.5.0`. The CodeSandbox versions of the examples still reflect `0.4` and earlier APIs and are in the process of being updated.
> The source code for the book is available [here](https://github.com/leptos-rs/leptos/tree/main/docs/book). PRs for typos or clarification are always welcome.

View File

@@ -23,15 +23,15 @@ cargo init leptos-tutorial
`cd` into your new `leptos-tutorial` project and add `leptos` as a dependency
```bash
cargo add leptos --features=csr,nightly
cargo add leptos@0.5.0 --features=csr,nightly
```
> **Note**: This version of the book reflects the Leptos 0.5 release. The CodeSandbox examples have not yet been updated from 0.4 and earlier versions.
> **Note**: This version of the book reflects the upcoming Leptos 0.5.0 release. The CodeSandbox examples have not yet been updated from 0.4 and earlier versions.
Or you can leave off `nightly` if you're using stable Rust
```bash
cargo add leptos --features=csr
cargo add leptos@0.5.0 --features=csr
```
> Using `nightly` Rust, and the `nightly` feature in Leptos enables the function-call syntax for signal getters and setters that is used in most of this book.

View File

@@ -47,14 +47,3 @@ Helix, in `.helix/languages.toml`:
name = "rust"
config = { procMacro = {ignored = {leptos_macro = ["component"]}}}
```
```admonish info
The Jetbrains `intellij-rust` plugin (RustRover as well) currently does not support dynamic config for macro exclusion.
However, the project currently maintains a hardcoded list of excluded macros.
As soon as [this open PR](https://github.com/intellij-rust/intellij-rust/pull/10873) is merged, the `component` and
`server` macro will be excluded automatically without additional configuration needed.
Update (2023/10/02):
The `intellij-rust` plugin got deprecated in favor of RustRover at the same time the PR was opened, but an official
support request was made to integrate the contents of this PR.
```

View File

@@ -50,7 +50,7 @@ use stylers::style;
#[component]
pub fn App() -> impl IntoView {
let styler_class = style! { "App",
##two{
#two{
color: blue;
}
div.one{

View File

@@ -229,9 +229,9 @@ fn DynamicList(
// can only grow, because moving items around inside the list
// means their indices will change and they will all rerender
key=|counter| counter.0
// `children` receives each item from your `each` iterator
// the view function receives each item from your `each` iterator
// and returns a view
children=move |(id, (count, set_count))| {
view=move |(id, (count, set_count))| {
view! {
<li>
<button

View File

@@ -5,4 +5,4 @@ edition = "2021"
[dependencies]
leptos = { path = "../../leptos", features = ["csr", "nightly"] }
gtk = { version = "0.5.0", package = "gtk4" }
gtk = { version = "0.5.0", package = "gtk4" }

View File

@@ -70,7 +70,7 @@ pub fn App() -> impl IntoView {
fetch_user_info.dispatch(());
}
log::debug!("User is logged in: {}", logged_in.get_untracked());
log::debug!("User is logged in: {}", logged_in.get());
// -- effects -- //

View File

@@ -1118,21 +1118,8 @@ where
if let Some(status) = res_options.status {
*res.status_mut() = status
}
let headers = res.headers_mut();
let mut res_headers = res_options.headers.clone();
headers.extend(res_headers.drain());
// This one doesn't use generate_response(), so we need to do this seperately
if !headers.contains_key(http::header::CONTENT_TYPE) {
// Set the Content Type headers on all responses. This makes Firefox show the page source
// without complaining
headers.insert(
http::header::CONTENT_TYPE,
HeaderValue::from_str("text/html; charset=utf-8")
.unwrap(),
);
}
res.headers_mut().extend(res_headers.drain());
res
}

View File

@@ -178,7 +178,7 @@ pub mod error {
}
#[cfg(all(target_arch = "wasm32", feature = "template_macro"))]
pub use leptos_macro::template;
#[cfg(not(all(target_arch = "wasm32", feature = "template_macro")))]
#[cfg(not(any(target_arch = "wasm32", feature = "template_macro")))]
pub use leptos_macro::view as template;
pub use leptos_macro::{component, island, server, slot, view, Params};
pub use leptos_reactive::*;
@@ -230,12 +230,8 @@ pub use wasm_bindgen; // used in islands
feature = "template_macro"
))]
pub use web_sys; // used in islands
mod children;
mod view_fn;
pub use children::*;
pub use view_fn::*;
extern crate self as leptos;
/// A type for taking anything that implements [`IntoAttribute`].

View File

@@ -1,4 +1,4 @@
use leptos::{component, ChildrenFn, ViewFn};
use leptos::{component, ChildrenFn};
use leptos_dom::IntoView;
use leptos_reactive::{create_memo, signal_prelude::*};
@@ -6,7 +6,10 @@ use leptos_reactive::{create_memo, signal_prelude::*};
/// and show the fallback when it is `false`, without rerendering every time
/// the condition changes.
///
/// The fallback prop is optional and defaults to rendering nothing.
/// *Note*: Because of the nature of generic arguments, its not really possible
/// to make the `fallback` optional. If you want an empty fallback state—in other
/// words, if you want to show the children if `when` is true and noting otherwise—use
/// `fallback=|_| ()` (i.e., a fallback function that returns the unit type `()`).
///
/// ```rust
/// # use leptos_reactive::*;
@@ -31,22 +34,23 @@ use leptos_reactive::{create_memo, signal_prelude::*};
tracing::instrument(level = "info", skip_all)
)]
#[component]
pub fn Show<W>(
pub fn Show<F, W, IV>(
/// The children will be shown whenever the condition in the `when` closure returns `true`.
children: ChildrenFn,
/// A closure that returns a bool that determines whether this thing runs
when: W,
/// A closure that returns what gets rendered if the when statement is false. By default this is the empty view.
#[prop(optional, into)]
fallback: ViewFn,
/// A closure that returns what gets rendered if the when statement is false
fallback: F,
) -> impl IntoView
where
W: Fn() -> bool + 'static,
F: Fn() -> IV + 'static,
IV: IntoView,
{
let memoized_when = create_memo(move |_| when());
move || match memoized_when.get() {
true => children().into_view(),
false => fallback.run(),
false => fallback().into_view(),
}
}

View File

@@ -1,8 +1,5 @@
use leptos::ViewFn;
use leptos_dom::{DynChild, HydrationCtx, IntoView};
use leptos_macro::component;
#[cfg(feature = "hydrate")]
use leptos_reactive::SharedContext;
#[cfg(any(feature = "csr", feature = "hydrate"))]
use leptos_reactive::SignalGet;
use leptos_reactive::{
@@ -60,14 +57,15 @@ use std::rc::Rc;
tracing::instrument(level = "info", skip_all)
)]
#[component]
pub fn Suspense<V>(
/// Returns a fallback UI that will be shown while `async` [`Resource`](leptos_reactive::Resource)s are still loading. By default this is the empty view.
#[prop(optional, into)]
fallback: ViewFn,
pub fn Suspense<F, E, V>(
/// Returns a fallback UI that will be shown while `async` [`Resource`](leptos_reactive::Resource)s are still loading.
fallback: F,
/// Children will be displayed once all `async` [`Resource`](leptos_reactive::Resource)s have resolved.
children: Rc<dyn Fn() -> V>,
) -> impl IntoView
where
F: Fn() -> E + 'static,
E: IntoView,
V: IntoView + 'static,
{
let orig_children = children;
@@ -77,11 +75,8 @@ where
let owner =
Owner::current().expect("<Suspense/> created with no reactive owner");
let current_id = HydrationCtx::next_component();
// provide this SuspenseContext to any resources below it
// run in a memo so the children are children of this parent
#[cfg(not(feature = "hydrate"))]
let children = create_memo({
let orig_children = Rc::clone(&orig_children);
move |_| {
@@ -89,32 +84,17 @@ where
orig_children().into_view()
}
});
#[cfg(feature = "hydrate")]
let children = create_memo({
let orig_children = Rc::clone(&orig_children);
move |_| {
provide_context(context);
if SharedContext::fragment_has_local_resources(
&current_id.to_string(),
) {
HydrationCtx::with_hydration_off({
let orig_children = Rc::clone(&orig_children);
move || orig_children().into_view()
})
} else {
orig_children().into_view()
}
}
});
// likewise for the fallback
let fallback = create_memo({
move |_| {
provide_context(context);
fallback.run()
fallback().into_view()
}
});
let current_id = HydrationCtx::next_component();
#[cfg(any(feature = "csr", feature = "hydrate"))]
let ready = context.ready();
@@ -146,11 +126,6 @@ where
DynChild::new(move || children_rendered.clone())
.into_view()
})
} else if context.has_any_local() {
SharedContext::register_local_fragment(
current_id.to_string(),
);
fallback.get_untracked()
}
// show the fallback, but also prepare to stream HTML
else {

View File

@@ -1,4 +1,3 @@
use leptos::ViewFn;
use leptos_dom::{Fragment, HydrationCtx, IntoView, View};
use leptos_macro::component;
use leptos_reactive::{
@@ -67,10 +66,9 @@ use std::{
tracing::instrument(level = "info", skip_all)
)]
#[component(transparent)]
pub fn Transition(
/// Will be displayed while resources are pending. By default this is the empty view.
#[prop(optional, into)]
fallback: ViewFn,
pub fn Transition<F, E>(
/// Will be displayed while resources are pending.
fallback: F,
/// A function that will be called when the component transitions into or out of
/// the `pending` state, with its argument indicating whether it is pending (`true`)
/// or not pending (`false`).
@@ -78,7 +76,11 @@ pub fn Transition(
set_pending: Option<SignalSetter<bool>>,
/// Will be displayed once all resources have resolved.
children: Box<dyn Fn() -> Fragment>,
) -> impl IntoView {
) -> impl IntoView
where
F: Fn() -> E + 'static,
E: IntoView,
{
let prev_children = Rc::new(RefCell::new(None::<View>));
let first_run = create_rw_signal(true);
@@ -103,12 +105,12 @@ pub fn Transition(
if let Some(prev_children) = &*prev_child.borrow() {
if is_first_run || was_first_run {
fallback.run()
fallback().into_view()
} else {
prev_children.clone()
}
} else {
fallback.run()
fallback().into_view()
}
}
})

View File

@@ -1,30 +0,0 @@
use leptos_dom::{IntoView, View};
use std::rc::Rc;
/// New-type wrapper for the a function that returns a view with `From` and `Default` traits implemented
/// to enable optional props in for example `<Show>` and `<Suspense>`.
#[derive(Clone)]
pub struct ViewFn(Rc<dyn Fn() -> View>);
impl Default for ViewFn {
fn default() -> Self {
Self(Rc::new(|| ().into_view()))
}
}
impl<F, IV> From<F> for ViewFn
where
F: Fn() -> IV + 'static,
IV: IntoView,
{
fn from(value: F) -> Self {
Self(Rc::new(move || value().into_view()))
}
}
impl ViewFn {
/// Execute the wrapped function
pub fn run(&self) -> View {
(self.0)()
}
}

View File

@@ -250,19 +250,6 @@ impl HydrationCtx {
value
}
#[doc(hidden)]
#[cfg(feature = "hydrate")]
pub fn with_hydration_off<T>(f: impl FnOnce() -> T) -> T {
let prev = IS_HYDRATING.with(|is_hydrating| {
let prev = is_hydrating.get();
is_hydrating.set(false);
prev
});
let value = f();
IS_HYDRATING.with(|is_hydrating| is_hydrating.set(prev));
value
}
/// Whether the UI is currently in the process of hydrating from the server-sent HTML.
#[inline(always)]
pub fn is_hydrating() -> bool {

View File

@@ -203,9 +203,6 @@ pub fn render_to_stream_with_prefix_undisposed_with_context_and_block_replacemen
.map(|nonce| format!(" nonce=\"{nonce}\""))
.unwrap_or_default();
let local_only = SharedContext::fragments_with_local_resources();
let local_only = serde_json::to_string(&local_only).unwrap();
let mut blocking_fragments = FuturesUnordered::new();
let fragments = FuturesUnordered::new();
@@ -229,8 +226,7 @@ pub fn render_to_stream_with_prefix_undisposed_with_context_and_block_replacemen
let resolvers = format!(
"<script{nonce_str}>__LEPTOS_PENDING_RESOURCES = \
{pending_resources};__LEPTOS_RESOLVED_RESOURCES = new \
Map();__LEPTOS_RESOURCE_RESOLVERS = new \
Map();__LEPTOS_LOCAL_ONLY = {local_only};</script>"
Map();__LEPTOS_RESOURCE_RESOLVERS = new Map();</script>"
);
if replace_blocks {

View File

@@ -125,9 +125,6 @@ pub fn render_to_stream_in_order_with_prefix_undisposed_with_context(
.map(|nonce| format!(" nonce=\"{nonce}\""))
.unwrap_or_default();
let local_only = SharedContext::fragments_with_local_resources();
let local_only = serde_json::to_string(&local_only).unwrap();
let stream = futures::stream::once({
let nonce_str = nonce_str.clone();
async move {
@@ -139,7 +136,6 @@ pub fn render_to_stream_in_order_with_prefix_undisposed_with_context(
__LEPTOS_PENDING_RESOURCES = {pending_resources};
__LEPTOS_RESOLVED_RESOURCES = new Map();
__LEPTOS_RESOURCE_RESOLVERS = new Map();
__LEPTOS_LOCAL_ONLY = {local_only};
</script>
"#
)

View File

@@ -511,7 +511,6 @@ impl ToTokens for Model {
#[doc = ""]
#component_fn_prop_docs
#[allow(non_snake_case, clippy::too_many_arguments)]
#[allow(clippy::needless_lifetimes)]
#tracing_instrument_attr
#vis fn #name #impl_generics (
#props_arg

View File

@@ -164,7 +164,7 @@ mod slot;
/// # runtime.dispose();
/// ```
///
/// Class names can include dashes, and since v0.5.0 can include a dash-separated segment of only numbers.
/// Class names can include dashes, and since leptos v0.5.0 can include a dash-separated segment of only numbers.
/// ```rust
/// # use leptos::*;
/// # let runtime = create_runtime();

View File

@@ -284,7 +284,7 @@ fn element_to_tokens_ssr(
template.push_str(" {}");
holes.push(quote! {
{#end}.into_iter().filter_map(|(name, attr)| {
Some(format!("{}=\"{}\"", name, ::leptos::leptos_dom::ssr::escape_attr(&attr.as_nameless_value_string()?)))
Some(format!("{}={}", name, ::leptos::leptos_dom::ssr::escape_attr(&attr.as_nameless_value_string()?)))
}).collect::<Vec<_>>().join(" ")
});
};

View File

@@ -85,12 +85,10 @@ impl<In> fmt::Debug for Callback<In> {
impl<In, Out> Clone for Callback<In, Out> {
fn clone(&self) -> Self {
*self
Self(self.0)
}
}
impl<In, Out> Copy for Callback<In, Out> {}
impl<In, Out> Callback<In, Out> {
/// Creates a new callback from the given function.
pub fn new<F>(f: F) -> Callback<In, Out>

View File

@@ -20,8 +20,6 @@ pub struct SharedContext {
pub resolved_resources: HashMap<ResourceId, String>,
/// Suspended fragments that have not yet resolved.
pub pending_fragments: HashMap<String, FragmentData>,
/// Suspense fragments that contain only local resources.
pub fragments_with_local_resources: HashSet<String>,
#[cfg(feature = "experimental-islands")]
pub no_hydrate: bool,
#[cfg(all(feature = "hydrate", feature = "experimental-islands"))]
@@ -110,7 +108,6 @@ impl SharedContext {
is_ready: Some(Box::pin(async move {
rx3.next().await;
})),
local_only: context.has_local_only(),
},
);
})
@@ -188,44 +185,6 @@ impl SharedContext {
});
}
}
#[cfg_attr(
any(debug_assertions, features = "ssr"),
instrument(level = "trace", skip_all,)
)]
pub fn fragment_has_local_resources(fragment: &str) -> bool {
with_runtime(|runtime| {
let mut shared_context = runtime.shared_context.borrow_mut();
shared_context
.fragments_with_local_resources
.remove(fragment)
})
.unwrap_or_default()
}
#[cfg_attr(
any(debug_assertions, features = "ssr"),
instrument(level = "trace", skip_all,)
)]
pub fn fragments_with_local_resources() -> HashSet<String> {
with_runtime(|runtime| {
let mut shared_context = runtime.shared_context.borrow_mut();
std::mem::take(&mut shared_context.fragments_with_local_resources)
})
.unwrap_or_default()
}
#[cfg_attr(
any(debug_assertions, features = "ssr"),
instrument(level = "trace", skip_all,)
)]
pub fn register_local_fragment(key: String) {
with_runtime(|runtime| {
let mut shared_context = runtime.shared_context.borrow_mut();
shared_context.fragments_with_local_resources.insert(key);
})
.unwrap_or_default()
}
}
/// Represents its pending `<Suspense/>` fragment.
@@ -238,8 +197,6 @@ pub struct FragmentData {
pub should_block: bool,
/// Future that will resolve when the fragment is ready.
pub is_ready: Option<PinnedFuture<()>>,
/// Whether the fragment contains only local resources.
pub local_only: bool,
}
impl std::fmt::Debug for SharedContext {
@@ -272,17 +229,6 @@ impl Default for SharedContext {
serde_wasm_bindgen::from_value(pr).map_err(|_| ())
})
.unwrap();
let fragments_with_local_resources = js_sys::Reflect::get(
&web_sys::window().unwrap(),
&wasm_bindgen::JsValue::from_str("__LEPTOS_LOCAL_ONLY"),
);
let fragments_with_local_resources: HashSet<String> =
fragments_with_local_resources
.map_err(|_| ())
.and_then(|pr| {
serde_wasm_bindgen::from_value(pr).map_err(|_| ())
})
.unwrap_or_default();
let resolved_resources = js_sys::Reflect::get(
&web_sys::window().unwrap(),
@@ -298,7 +244,6 @@ impl Default for SharedContext {
//events: Default::default(),
pending_resources,
resolved_resources,
fragments_with_local_resources,
pending_fragments: Default::default(),
#[cfg(feature = "experimental-islands")]
no_hydrate: true,
@@ -317,7 +262,6 @@ impl Default for SharedContext {
pending_resources: Default::default(),
resolved_resources: Default::default(),
pending_fragments: Default::default(),
fragments_with_local_resources: Default::default(),
#[cfg(feature = "experimental-islands")]
no_hydrate: true,
#[cfg(all(

View File

@@ -80,17 +80,13 @@ extern crate tracing;
#[macro_use]
mod signal;
pub mod callback;
mod callback;
mod context;
#[macro_use]
mod diagnostics;
mod effect;
mod hydration;
// contains "private" implementation details right now.
// could make this unhidden in the future if needed.
// macro_export makes it public from the crate root anyways
#[doc(hidden)]
pub mod macros;
mod macros;
mod memo;
mod node;
pub mod oco;

View File

@@ -17,9 +17,8 @@ pub(crate) use debug_warn;
/// Provides a simpler way to use [`SignalWith::with`](crate::SignalWith::with).
///
/// This macro also supports [stored values](crate::StoredValue). If you would
/// like to distinguish between the two, you can also use [`with_value`](crate::with_value)
/// for stored values only.
/// To use with [stored values](crate::StoredValue), see the [`with_value`](crate::with_value)
/// macro instead.
///
/// The general syntax looks like:
/// ```ignore
@@ -33,13 +32,15 @@ pub(crate) use debug_warn;
///
/// # Examples
/// ```
/// # use leptos_reactive::*;
/// # use leptos::*;
/// # let runtime = create_runtime();
/// # if !cfg!(any(feature = "csr", feature = "hydrate")) {
/// let (first, _) = create_signal("Bob".to_string());
/// let (middle, _) = create_signal("J.".to_string());
/// let (last, _) = create_signal("Smith".to_string());
/// let name = with!(|first, middle, last| format!("{first} {middle} {last}"));
/// assert_eq!(name, "Bob J. Smith");
/// # };
/// # runtime.dispose();
/// ```
///
@@ -66,22 +67,16 @@ pub(crate) use debug_warn;
#[macro_export]
macro_rules! with {
(|$ident:ident $(,)?| $body:expr) => {
$crate::macros::__private::Withable::call_with(&$ident, |$ident| $body)
$ident.with(|$ident| $body)
};
(move |$ident:ident $(,)?| $body:expr) => {
$crate::macros::__private::Withable::call_with(&$ident, move |$ident| $body)
$ident.with(move |$ident| $body)
};
(|$first:ident, $($rest:ident),+ $(,)? | $body:expr) => {
$crate::macros::__private::Withable::call_with(
&$first,
|$first| with!(|$($rest),+| $body)
)
$first.with(|$first| with!(|$($rest),+| $body))
};
(move |$first:ident, $($rest:ident),+ $(,)? | $body:expr) => {
$crate::macros::__private::Withable::call_with(
&$first,
move |$first| with!(|$($rest),+| $body)
)
$first.with(move |$first| with!(move |$($rest),+| $body))
};
}
@@ -91,10 +86,6 @@ macro_rules! with {
/// To use with [signals](crate::SignalWith::with), see the [`with!`] macro
/// instead.
///
/// Note that the [`with!`] macro also works with
/// [`StoredValue`](crate::StoredValue). Use this macro if you would like to
/// distinguish between signals and stored values.
///
/// The general syntax looks like:
/// ```ignore
/// with_value!(|capture1, capture2, ...| body);
@@ -107,8 +98,9 @@ macro_rules! with {
///
/// # Examples
/// ```
/// # use leptos_reactive::*;
/// # use leptos::*;
/// # let runtime = create_runtime();
/// # if !cfg!(any(feature = "csr", feature = "hydrate")) {
/// let first = store_value("Bob".to_string());
/// let middle = store_value("J.".to_string());
/// let last = store_value("Smith".to_string());
@@ -116,6 +108,7 @@ macro_rules! with {
/// format!("{first} {middle} {last}")
/// });
/// assert_eq!(name, "Bob J. Smith");
/// # };
/// # runtime.dispose();
/// ```
/// The `with_value!` macro in the above example expands to:
@@ -157,9 +150,8 @@ macro_rules! with_value {
/// Provides a simpler way to use
/// [`SignalUpdate::update`](crate::SignalUpdate::update).
///
/// This macro also supports [stored values](crate::StoredValue). If you would
/// like to distinguish between the two, you can also use [`update_value`](crate::update_value)
/// for stored values only.
/// To use with [stored values](crate::StoredValue), see the [`update_value`](crate::update_value)
/// macro instead.
///
/// The general syntax looks like:
/// ```ignore
@@ -173,12 +165,14 @@ macro_rules! with_value {
///
/// # Examples
/// ```
/// # use leptos_reactive::*;
/// # use leptos::*;
/// # let runtime = create_runtime();
/// # if !cfg!(any(feature = "csr", feature = "hydrate")) {
/// let a = create_rw_signal(1);
/// let b = create_rw_signal(2);
/// update!(|a, b| *a = *a + *b);
/// assert_eq!(a.get(), 3);
/// # };
/// # runtime.dispose();
/// ```
/// The `update!` macro in the above example expands to:
@@ -202,22 +196,16 @@ macro_rules! with_value {
#[macro_export]
macro_rules! update {
(|$ident:ident $(,)?| $body:expr) => {
$crate::macros::__private::Updatable::call_update(&$ident, |$ident| $body)
$ident.update(|$ident| $body)
};
(move |$ident:ident $(,)?| $body:expr) => {
$crate::macros::__private::Updatable::call_update(&$ident, move |$ident| $body)
$ident.update(move |$ident| $body)
};
(|$first:ident, $($rest:ident),+ $(,)? | $body:expr) => {
$crate::macros::__private::Updatable::call_update(
&$first,
|$first| update!(|$($rest),+| $body)
)
$first.update(|$first| update!(|$($rest),+| $body))
};
(move |$first:ident, $($rest:ident),+ $(,)? | $body:expr) => {
$crate::macros::__private::Updatable::call_update(
&$first,
move |$first| update!(|$($rest),+| $body)
)
$first.update(move |$first| update!(move |$($rest),+| $body))
};
}
@@ -227,10 +215,6 @@ macro_rules! update {
/// To use with [signals](crate::SignalUpdate::update), see the [`update`]
/// macro instead.
///
/// Note that the [`update!`] macro also works with
/// [`StoredValue`](crate::StoredValue). Use this macro if you would like to
/// distinguish between signals and stored values.
///
/// The general syntax looks like:
/// ```ignore
/// update_value!(|capture1, capture2, ...| body);
@@ -243,12 +227,14 @@ macro_rules! update {
///
/// # Examples
/// ```
/// # use leptos_reactive::*;
/// # use leptos::*;
/// # let runtime = create_runtime();
/// # if !cfg!(any(feature = "csr", feature = "hydrate")) {
/// let a = store_value(1);
/// let b = store_value(2);
/// update_value!(|a, b| *a = *a + *b);
/// assert_eq!(a.get_value(), 3);
/// # };
/// # runtime.dispose();
/// ```
/// The `update_value!` macro in the above example expands to:
@@ -283,62 +269,3 @@ macro_rules! update_value {
$first.update_value(move |$first| update_value!(move |$($rest),+| $body))
};
}
/// This is a private module intended to only be used by macros. Do not access
/// this directly!
#[doc(hidden)]
pub mod __private {
use crate::{SignalUpdate, SignalWith, StoredValue};
pub trait Withable {
type Value;
// don't use `&self` or r-a will suggest importing this trait
// and using it as a method
#[track_caller]
fn call_with<O>(item: &Self, f: impl FnOnce(&Self::Value) -> O) -> O;
}
impl<T> Withable for StoredValue<T> {
type Value = T;
#[inline(always)]
fn call_with<O>(item: &Self, f: impl FnOnce(&Self::Value) -> O) -> O {
item.with_value(f)
}
}
impl<S: SignalWith> Withable for S {
type Value = S::Value;
#[inline(always)]
fn call_with<O>(item: &Self, f: impl FnOnce(&Self::Value) -> O) -> O {
item.with(f)
}
}
pub trait Updatable {
type Value;
#[track_caller]
fn call_update(item: &Self, f: impl FnOnce(&mut Self::Value));
}
impl<T> Updatable for StoredValue<T> {
type Value = T;
#[inline(always)]
fn call_update(item: &Self, f: impl FnOnce(&mut Self::Value)) {
item.update_value(f)
}
}
impl<S: SignalUpdate> Updatable for S {
type Value = S::Value;
#[inline(always)]
fn call_update(item: &Self, f: impl FnOnce(&mut Self::Value)) {
item.update(f)
}
}
}

View File

@@ -5,11 +5,10 @@ use crate::SpecialNonReactiveZone;
use crate::{
create_isomorphic_effect, create_memo, create_render_effect, create_signal,
queue_microtask, runtime::with_runtime, serialization::Serializable,
signal_prelude::format_signal_warning, spawn::spawn_local,
suspense::LocalStatus, use_context, GlobalSuspenseContext, Memo,
ReadSignal, ScopeProperty, Signal, SignalDispose, SignalGet,
SignalGetUntracked, SignalSet, SignalUpdate, SignalWith, SuspenseContext,
WriteSignal,
signal_prelude::format_signal_warning, spawn::spawn_local, use_context,
GlobalSuspenseContext, Memo, ReadSignal, ScopeProperty, Signal,
SignalDispose, SignalGet, SignalGetUntracked, SignalSet, SignalUpdate,
SignalWith, SuspenseContext, WriteSignal,
};
use std::{
any::Any,
@@ -1179,16 +1178,7 @@ where
let serializable = self.serializable;
if let Some(suspense_cx) = &suspense_cx {
if serializable != ResourceSerialization::Local {
suspense_cx.local_status.update_value(|status| {
*status = Some(match status {
None => LocalStatus::SerializableOnly,
Some(LocalStatus::LocalOnly) => LocalStatus::LocalOnly,
Some(LocalStatus::Mixed) => LocalStatus::Mixed,
Some(LocalStatus::SerializableOnly) => {
LocalStatus::SerializableOnly
}
});
});
suspense_cx.has_local_only.set_value(false);
}
} else {
#[cfg(not(all(feature = "hydrate", debug_assertions)))]
@@ -1472,11 +1462,6 @@ pub fn suppress_resource_load(suppress: bool) {
SUPPRESS_RESOURCE_LOAD.with(|w| w.set(suppress));
}
#[doc(hidden)]
pub fn is_suppressing_resource_load() -> bool {
SUPPRESS_RESOURCE_LOAD.with(|w| w.get())
}
impl<S, T> SignalDispose for Resource<S, T>
where
S: 'static,

View File

@@ -1,7 +1,7 @@
use crate::{
create_isomorphic_effect, on_cleanup, runtime::untrack, store_value, Memo,
ReadSignal, RwSignal, SignalDispose, SignalGet, SignalGetUntracked,
SignalStream, SignalWith, SignalWithUntracked, StoredValue,
ReadSignal, RwSignal, SignalGet, SignalGetUntracked, SignalStream,
SignalWith, SignalWithUntracked, StoredValue,
};
/// Helper trait for converting `Fn() -> T` closures into
@@ -320,16 +320,6 @@ impl<T: Clone> SignalGet for Signal<T> {
}
}
impl<T> SignalDispose for Signal<T> {
fn dispose(self) {
match self.inner {
SignalTypes::ReadSignal(s) => s.dispose(),
SignalTypes::Memo(m) => m.dispose(),
SignalTypes::DerivedSignal(s) => s.dispose(),
}
}
}
impl<T: Clone> SignalStream<T> for Signal<T> {
fn to_stream(&self) -> std::pin::Pin<Box<dyn futures::Stream<Item = T>>> {
match self.inner {

View File

@@ -203,13 +203,6 @@ impl<T> StoredValue<T> {
.flatten()
}
/// Disposes of the stored value
pub fn dispose(self) {
_ = with_runtime(|runtime| {
runtime.stored_values.borrow_mut().remove(self.id);
});
}
/// Sets the stored value.
///
/// # Examples

View File

@@ -16,17 +16,10 @@ pub struct SuspenseContext {
pub pending_resources: ReadSignal<usize>,
set_pending_resources: WriteSignal<usize>,
pub(crate) pending_serializable_resources: RwSignal<usize>,
pub(crate) local_status: StoredValue<Option<LocalStatus>>,
pub(crate) has_local_only: StoredValue<bool>,
pub(crate) should_block: StoredValue<bool>,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub(crate) enum LocalStatus {
LocalOnly,
Mixed,
SerializableOnly,
}
/// A single, global suspense context that will be checked when resources
/// are read. This wont be “blocked” by lower suspense components. This is
/// useful for e.g., holding route transitions.
@@ -61,15 +54,7 @@ impl SuspenseContext {
/// Whether the suspense contains local resources at this moment,
/// and therefore can't be serialized
pub fn has_local_only(&self) -> bool {
matches!(self.local_status.get_value(), Some(LocalStatus::LocalOnly))
}
/// Whether the suspense contains any local resources at this moment.
pub fn has_any_local(&self) -> bool {
matches!(
self.local_status.get_value(),
Some(LocalStatus::LocalOnly) | Some(LocalStatus::Mixed)
)
self.has_local_only.get_value()
}
/// Whether any blocking resources are read under this suspense context,
@@ -117,13 +102,13 @@ impl SuspenseContext {
pub fn new() -> Self {
let (pending_resources, set_pending_resources) = create_signal(0);
let pending_serializable_resources = create_rw_signal(0);
let local_status = store_value(None);
let has_local_only = store_value(true);
let should_block = store_value(false);
Self {
pending_resources,
set_pending_resources,
pending_serializable_resources,
local_status,
has_local_only,
should_block,
}
}
@@ -132,29 +117,11 @@ impl SuspenseContext {
pub fn increment(&self, serializable: bool) {
let setter = self.set_pending_resources;
let serializable_resources = self.pending_serializable_resources;
let local_status = self.local_status;
let has_local_only = self.has_local_only;
setter.update(|n| *n += 1);
if serializable {
serializable_resources.update(|n| *n += 1);
local_status.update_value(|status| {
*status = Some(match status {
None => LocalStatus::SerializableOnly,
Some(LocalStatus::LocalOnly) => LocalStatus::LocalOnly,
Some(LocalStatus::Mixed) => LocalStatus::Mixed,
Some(LocalStatus::SerializableOnly) => {
LocalStatus::SerializableOnly
}
});
});
} else {
local_status.update_value(|status| {
*status = Some(match status {
None => LocalStatus::LocalOnly,
Some(LocalStatus::LocalOnly) => LocalStatus::LocalOnly,
Some(LocalStatus::Mixed) => LocalStatus::Mixed,
Some(LocalStatus::SerializableOnly) => LocalStatus::Mixed,
});
});
has_local_only.set_value(false);
}
}

View File

@@ -1,7 +1,7 @@
use crate::{ServerFn, ServerFnError};
use leptos_reactive::{
batch, create_rw_signal, is_suppressing_resource_load, signal_prelude::*,
spawn_local, store_value, ReadSignal, RwSignal, StoredValue,
batch, create_rw_signal, signal_prelude::*, spawn_local, store_value,
ReadSignal, RwSignal, StoredValue,
};
use std::{cell::Cell, future::Future, pin::Pin, rc::Rc};
@@ -228,30 +228,28 @@ where
tracing::instrument(level = "trace", skip_all,)
)]
pub fn dispatch(&self, input: I) {
if !is_suppressing_resource_load() {
let fut = (self.action_fn)(&input);
self.input.set(Some(input));
let input = self.input;
let version = self.version;
let pending = self.pending;
let pending_dispatches = Rc::clone(&self.pending_dispatches);
let value = self.value;
pending.set(true);
pending_dispatches.set(pending_dispatches.get().saturating_sub(1));
spawn_local(async move {
let new_value = fut.await;
batch(move || {
value.set(Some(new_value));
input.set(None);
version.update(|n| *n += 1);
pending_dispatches
.set(pending_dispatches.get().saturating_sub(1));
if pending_dispatches.get() == 0 {
pending.set(false);
}
});
})
}
let fut = (self.action_fn)(&input);
self.input.set(Some(input));
let input = self.input;
let version = self.version;
let pending = self.pending;
let pending_dispatches = Rc::clone(&self.pending_dispatches);
let value = self.value;
pending.set(true);
pending_dispatches.set(pending_dispatches.get().saturating_sub(1));
spawn_local(async move {
let new_value = fut.await;
batch(move || {
value.set(Some(new_value));
input.set(None);
version.update(|n| *n += 1);
pending_dispatches
.set(pending_dispatches.get().saturating_sub(1));
if pending_dispatches.get() == 0 {
pending.set(false);
}
});
})
}
}

View File

@@ -1,7 +1,7 @@
use crate::{ServerFn, ServerFnError};
use leptos_reactive::{
create_rw_signal, is_suppressing_resource_load, signal_prelude::*,
spawn_local, store_value, untrack, ReadSignal, RwSignal, StoredValue,
create_rw_signal, signal_prelude::*, spawn_local, store_value, untrack,
ReadSignal, RwSignal, StoredValue,
};
use std::{future::Future, pin::Pin, rc::Rc};
@@ -210,35 +210,33 @@ where
tracing::instrument(level = "trace", skip_all,)
)]
pub fn dispatch(&self, input: I) {
if !is_suppressing_resource_load() {
let fut = (self.action_fn)(&input);
let fut = (self.action_fn)(&input);
let submission = Submission {
input: create_rw_signal(Some(input)),
value: create_rw_signal(None),
pending: create_rw_signal(true),
canceled: create_rw_signal(false),
};
let submission = Submission {
input: create_rw_signal(Some(input)),
value: create_rw_signal(None),
pending: create_rw_signal(true),
canceled: create_rw_signal(false),
};
self.submissions.update(|subs| subs.push(submission));
self.submissions.update(|subs| subs.push(submission));
let canceled = submission.canceled;
let input = submission.input;
let pending = submission.pending;
let value = submission.value;
let version = self.version;
let canceled = submission.canceled;
let input = submission.input;
let pending = submission.pending;
let value = submission.value;
let version = self.version;
spawn_local(async move {
let new_value = fut.await;
let canceled = untrack(move || canceled.get());
if !canceled {
value.set(Some(new_value));
}
input.set(None);
pending.set(false);
version.update(|n| *n += 1);
})
}
spawn_local(async move {
let new_value = fut.await;
let canceled = untrack(move || canceled.get());
if !canceled {
value.set(Some(new_value));
}
input.set(None);
pending.set(false);
version.update(|n| *n += 1);
})
}
/// The set of all submissions to this multi-action.

View File

@@ -1,6 +1,6 @@
[package]
name = "leptos_meta"
version = "0.5.1"
version = "0.5.0"
edition = "2021"
authors = ["Greg Johnston"]
license = "MIT"

View File

@@ -149,15 +149,9 @@ pub fn Html(
}
} else if #[cfg(feature = "ssr")] {
let meta = crate::use_head();
if lang.is_some() {
*meta.html.lang.borrow_mut() = lang;
}
if dir.is_some() {
*meta.html.dir.borrow_mut() = dir;
}
if class.is_some() {
*meta.html.class.borrow_mut() = class;
}
*meta.html.lang.borrow_mut() = lang;
*meta.html.dir.borrow_mut() = dir;
*meta.html.class.borrow_mut() = class;
meta.html.attributes.borrow_mut().extend(attributes);
} else {
_ = lang;

View File

@@ -1,6 +1,6 @@
[package]
name = "leptos_router"
version = "0.5.1"
version = "0.5.0"
edition = "2021"
authors = ["Greg Johnston"]
license = "MIT"

View File

@@ -27,6 +27,7 @@ impl Animation {
outro,
intro,
intro_back,
finally,
..
} = self;
match current {
@@ -35,8 +36,10 @@ impl Animation {
AnimationState::Start
} else if intro.is_some() {
AnimationState::Intro
} else {
} else if finally.is_some() {
AnimationState::Finally
} else {
AnimationState::Start
};
(next, true)
}
@@ -47,21 +50,37 @@ impl Animation {
AnimationState::IntroBack
} else if intro.is_some() {
AnimationState::Intro
} else {
} else if finally.is_some() {
AnimationState::Finally
} else {
AnimationState::Start
};
(next, true)
}
AnimationState::Start => {
let next = if intro.is_some() {
AnimationState::Intro
} else {
} else if finally.is_some() {
AnimationState::Finally
} else {
AnimationState::Start
};
(next, false)
}
AnimationState::Intro => (AnimationState::Finally, false),
AnimationState::IntroBack => (AnimationState::Finally, false),
AnimationState::Intro => {
if finally.is_some() {
(AnimationState::Finally, false)
} else {
(AnimationState::Start, false)
}
}
AnimationState::IntroBack => {
if finally.is_some() {
(AnimationState::Finally, false)
} else {
(AnimationState::Start, false)
}
}
AnimationState::Finally => {
if outro.is_some() {
if is_back {
@@ -77,8 +96,10 @@ impl Animation {
} else {
(AnimationState::Intro, false)
}
} else {
} else if finally.is_some() {
(AnimationState::Finally, true)
} else {
(AnimationState::Start, true)
}
}
}

View File

@@ -179,7 +179,7 @@ pub fn AnimatedRoutes(
};
let is_back = use_is_back_navigation();
let (animation_state, set_animation_state) =
create_signal(AnimationState::Finally);
create_signal(AnimationState::Start);
let next_route = router.pathname();
let is_complete = Rc::new(Cell::new(true));
@@ -190,6 +190,7 @@ pub fn AnimatedRoutes(
move |prev: Option<&(AnimationState, String)>| {
let animation_state = animation_state.get();
let next_route = next_route.get();
logging::log!("{animation_state:?} {next_route:?}");
let prev_matches = prev
.map(|(_, r)| r)
.cloned()