Compare commits

...

1599 Commits

Author SHA1 Message Date
Greg Johnston
047f0dda0e chore: clear clippy warnings 2023-03-21 17:12:35 -04:00
Greg Johnston
c086ce21a6 v0.2.4 2023-03-21 17:12:35 -04:00
martin frances
d371b09eda clippy: simplify Box::pin() call. (#718) 2023-03-21 17:12:35 -04:00
Greg Johnston
5a1d249626 fix: <Transition/> behavior (#717) 2023-03-21 17:12:34 -04:00
Greg Johnston
aa0fa40eac docs: small fixes (#715) 2023-03-21 17:12:34 -04:00
Carlton Gibson
e36a2ba6df Used modulo rather than bitwise & for is_odd check.
The modulo operator is less of a head-scratcher for folks coming through here. The bitwise & is equally correct (clearly) but is likely to cause confusion if folks don't immediately see what's going on.
2023-03-21 17:12:34 -04:00
Greg Johnston
2072d69cad chore: clear warning and add exports of helpers with handles 2023-03-21 17:12:34 -04:00
Greg Johnston
2c5253c2ce chore: handle unbounded_send warnings 2023-03-21 17:12:34 -04:00
Greg Johnston
3558439577 feat: add Scope::batch() (#711) 2023-03-21 17:12:34 -04:00
Greg Johnston
b82a15cf67 feat: allow manual signal disposal before the scope is disposed (#710) 2023-03-21 17:12:34 -04:00
Greg Johnston
917733b393 feat: add set_interval_with_handle and deprecate set_interval (#709) 2023-03-21 17:12:34 -04:00
martin frances
b3c5982ac8 clippy: less .clone() calls, simpler pointer passing. (#707) 2023-03-21 17:12:34 -04:00
Alexis Fontaine
3da1b72a3f fix: view! macro not compiling with a non-default scope name (#704) 2023-03-21 17:12:34 -04:00
Greg Johnston
e65bde9a5a feat: add a debounce helper for event listeners (#691) 2023-03-21 17:12:34 -04:00
Elliot Waite
b6b4f51b11 feat: add request_animation_frame_with_handle and request_idle_callback_with_handle (#698) 2023-03-21 17:12:34 -04:00
Greg Johnston
396a3506ff fix: ignore view markers in DynChild hydration (closes issue #697) (#703) 2023-03-21 17:12:34 -04:00
Greg Johnston
1bde018ca0 fix issues in release mode (closes #700) (#701) 2023-03-21 17:12:34 -04:00
Greg Johnston
f7489054ba docs: beginning work on router docs (#682) 2023-03-21 17:12:34 -04:00
Elliot Waite
404a64943f examples: remove duplicate console_error_panic_hook::set_once() calls (#692) 2023-03-21 17:12:34 -04:00
Greg Johnston
6d16a3feb5 feat: support diffing inside component children in hot-reload (#690) 2023-03-21 17:12:34 -04:00
Greg Johnston
49932fda39 fix: hydration errors with <Suspense/> inside components in SSR mode (#688) 2023-03-21 17:12:34 -04:00
Vassil "Vasco" Kolarov
50a31977fd examples: added example using Tailwind, CSR (only) and Trunk (#666) 2023-03-21 17:12:34 -04:00
Greg Johnston
7639b941c6 fix: allow multiple <Suspense/> on same page during in-order or async rendering (#687) 2023-03-21 17:12:34 -04:00
ryndin32
9db245dec4 docs: typos (#685) 2023-03-21 17:12:34 -04:00
Brett Etter
de42efab11 Added IntoView for ReadSignal and RwSignal in the stable feature. (#677) 2023-03-21 17:12:34 -04:00
Greg Johnston
12e8428a84 Update README.md 2023-03-21 17:12:34 -04:00
Greg Johnston
f76f027ed5 fix: suppress spurious hydration warnings for tags in leptos_meta (#684) 2023-03-21 17:12:34 -04:00
Greg Johnston
959c99d7d8 fix: leaking stored values (#683) 2023-03-21 17:12:34 -04:00
Greg Johnston
12d4a93ac6 CI: add --release checks (#681) 2023-03-21 17:12:34 -04:00
Greg Johnston
421544cec4 feat: maintain order of sources and dependencies (#678) 2023-03-21 17:12:34 -04:00
Brett Etter
364b20ccce fix: release mode (#679) 2023-03-21 17:12:34 -04:00
Greg Johnston
8b2daf869b feat: new reactive system implementation (#637) 2023-03-21 17:12:34 -04:00
Greg Johnston
56f8f20d4a chore: apply cargo machete systematically (#671) 2023-03-21 17:12:34 -04:00
Greg Johnston
6d9cc626ff feat: <ActionForm/> improvements (#676) 2023-03-21 17:12:34 -04:00
Greg Johnston
633bcc5f5d v0.2.3: fix broken stable support (#670) 2023-03-21 17:12:34 -04:00
Greg Johnston
76a3ce8794 v0.2.2 (#667) 2023-03-21 17:12:34 -04:00
martin frances
ddd446fd16 clippy: signal_wrappers_read, was using .clone() when copy is available. (#665) 2023-03-21 17:12:34 -04:00
Elliot Waite
ab939ccf7f docs: typo fixes and other small changes to the docs (#662) 2023-03-21 17:12:34 -04:00
Greg Johnston
7f34135463 fix: apply patches to all instances of a view, not just the first one (#663) 2023-03-21 17:12:34 -04:00
Greg Johnston
c3c371b020 fix: text node issue in template macro (#661) 2023-03-21 17:12:34 -04:00
Charles Taylor
365ac41cad feat: impl Copy & Clone for MaybeSignal (#660) 2023-03-21 17:12:34 -04:00
Greg Johnston
71164c08aa feat: add fragment support for hot reloading and fix some stuff (#659) 2023-03-21 17:12:34 -04:00
Ben Wishovich
d19902b404 feat: provide Request<_> in context for Axum, enabling easier extractor use (#632) 2023-03-21 17:12:34 -04:00
martin frances
e4589551ca chore: cargo machete: leptos_macro - Removed unused crates. (#656) 2023-03-21 17:12:34 -04:00
Greg Johnston
dba6f9ee22 feat: impl IntoView for &Fragment (#655) 2023-03-21 17:12:34 -04:00
Pikhosh
6f7685ad3e fix: show console error instead warning for error! (#654) 2023-03-21 17:12:34 -04:00
ealmloff
2c944177d4 feat: make server functions work outside of WASM (#643) 2023-03-21 17:12:34 -04:00
Greg Johnston
d6e564105e docs: add create_effect chapter (#653) 2023-03-21 17:12:34 -04:00
zack.shen
35dcd12cfd docs: spelling error (#651) 2023-03-21 17:12:34 -04:00
martin frances
a9ba6ca930 chore: bumped typed-builder up to 0.14. (#648) 2023-03-21 17:12:34 -04:00
martin frances
d63e65cd53 chore: bump bytecheck to 0.7, remove deprecated simdutf8_std. (#647)
* bump bytecheck to 0.7, remove deprecated simdutf8_std.

* When using rkyv, must use the appropiate CheckBytes.
2023-03-21 17:12:34 -04:00
Greg Johnston
6bbbacc7cd chore: typo (closes issue #645) (#646) 2023-03-21 17:12:34 -04:00
Vanius Bittencourt
0746bc433c feat: refactor leptos_config to allow loading from string (#628) 2023-03-21 17:12:34 -04:00
martin frances
9e80837313 chore: cargo machete: Strip down leptos_server. (#644) 2023-03-21 17:12:34 -04:00
martin frances
70c9286626 chore: bump serde-wasm-bindgen to 0.5. (#639) 2023-03-21 17:12:34 -04:00
martin frances
a0e564e9be chore: <Form/> component Removed unused variables. (#640) 2023-03-21 17:12:34 -04:00
martin frances
84e21d58aa Bumped tower-http upto 0.4. (#638) 2023-03-21 17:12:34 -04:00
Greg Johnston
efab33beb1 fix: custom events (closes issue #641) (#642) 2023-03-21 17:12:34 -04:00
jo!
2028a95eed examples: add session_auth_axum (#589) 2023-03-21 17:12:34 -04:00
Greg Johnston
647f62ffa7 CI: split into three actions (#636) 2023-03-21 17:12:34 -04:00
erwanvivien
d5a39037e1 de-duplicate todomvc example (#634) 2023-03-21 17:12:34 -04:00
martin frances
020b793417 bump typed-builder to version 0.13. (#633) 2023-03-21 17:12:34 -04:00
jfloresremar
a7e94e3026 Update 04_iteration.md (#630) 2023-03-21 17:12:34 -04:00
IchHabeKeineNamen
e9541e6f60 docs: fix instruction typos (#631) 2023-03-21 17:12:34 -04:00
Greg Johnston
dbb8e6bde4 fix: boolean attributes in SSR (#629) 2023-03-21 17:12:34 -04:00
WafflePersonThing
b4a0d9363f fix: added missing attributes of events that don't bubble (#625)
references used:
- https://developer.mozilla.org/en-US/docs/Web/API/
- web archives of the above before jun 11th 2022, relevant: https://github.com/mdn/content/issues/19590
2023-03-21 17:12:34 -04:00
Greg Johnston
18caac3b2e feat: hot reloading support for cargo-leptos (#592) 2023-03-21 17:12:34 -04:00
Greg Johnston
091e05e610 docs: add a chapter on async actions and create_action (#623) 2023-03-21 17:12:34 -04:00
Greg Johnston
8f712966e3 CI: exclude rkyv combos with other serialization traits (#622) 2023-03-21 17:12:34 -04:00
Greg Johnston
aeb601f560 fix: suppress warnings caused by resource loading in generate_route_list (closes #582) (#621) 2023-03-21 17:12:34 -04:00
Greg Johnston
86e8fadc6d feat: allow easier client-side form validation (closes #413) (#620) 2023-03-21 17:12:34 -04:00
Greg Johnston
0a3935aa16 docs: add patterns for global state (closes #245) (#619) 2023-03-21 17:12:34 -04:00
Greg Johnston
62ed91c984 tests: use check instead of build in CI for disk space (#616) 2023-03-21 17:12:34 -04:00
Greg Johnston
8ecb63728c feat: allow multiple class names in view! macro class = (closes #612) (#614) 2023-03-21 17:12:34 -04:00
Greg Johnston
fd01a8ce30 docs: improve "Getting Started" page (#618) 2023-03-21 17:12:34 -04:00
Greg Johnston
9338fc4928 add note about running Trunk from root 2023-03-21 17:12:34 -04:00
martin frances
7eed00ae0e chore: clippy - simplified conditional logic in transition.rs. (#615) 2023-03-21 17:12:34 -04:00
Roland Fredenhagen
7911c4b613 feat: support expressions in #[prop(default=...)] (#611) 2023-03-21 17:12:34 -04:00
Ivan Agafonov
65b1518d6b docs: updated error handling code (#610)
code is from already updated example
2023-03-21 17:12:34 -04:00
Sergei Gnezdov
80c2d3ffff docs: fix compilation error, Issue #608 (#609)
Compiler reports error
F may not live long enough
2023-03-21 17:12:34 -04:00
Greg Johnston
e2c0bd1ad8 publish framework-independent server_fn crate (#605) 2023-03-21 17:12:34 -04:00
Ivan Agafonov
9819f28b2c docs: use create_node_ref instead of NodeRef::new (#607)
Code in the example already updated by someone
2023-03-21 17:12:34 -04:00
ealmloff
00730007d0 feat: make server functions framework agnostic (#596) 2023-03-21 17:12:34 -04:00
Greg Johnston
92920c2726 fix: memory leak in streaming SSR (closes issue #590) (#601) 2023-03-21 17:12:34 -04:00
Qwox
30a858defe fix: set new value before resetting input (#604)
Co-authored-by: Qwox <qwox@qwox.com>
2023-03-21 17:12:34 -04:00
Artem Makoven
1d6bf78b93 Fix typo in 03_components.md 2023-03-21 17:12:34 -04:00
Ivan Agafonov
d26fa60268 typo
_cx replaced with cx
2023-03-21 17:12:34 -04:00
Greg Johnston
4a685bfcdd fix SSR tests 2023-03-21 17:12:34 -04:00
Greg Johnston
2fadd92856 fix: don't re-set attributes found in HTML during hydration (closes #597) 2023-03-21 17:12:34 -04:00
Greg Johnston
19d2a1dfa7 fix: restore SSR fast-path support 2023-03-21 17:12:34 -04:00
Greg Johnston
6c86700666 examples: include missing examples in CI (#598) 2023-03-21 17:12:34 -04:00
Brendon Otto
6cb378e02a example: update README.md (#595)
Incorrect framework referenced
2023-03-21 17:12:34 -04:00
Greg Johnston
2b68fa6bc0 fix: mouseenter and mouseleave do not bubble (#593) 2023-03-21 17:12:34 -04:00
Thomas Kratz
c18847eb55 fix: make counter test compile (#588) 2023-03-21 17:12:34 -04:00
Azz
d851803f13 feat: support rkyv encoding (#577) 2023-03-21 17:12:34 -04:00
Greg Johnston
c122bbf9fa perf: improvements to event delegation and element creation in <For/> (#579) 2023-03-21 17:12:34 -04:00
g-re-g
ac8201877a fix: correct scheme handling in router, and improve matching code by removing regexes (#569) 2023-03-21 17:12:34 -04:00
Greg Johnston
0bc02df77f v0.2.0 2023-03-21 17:12:34 -04:00
tanguy-lf
d210d53f48 examples: add ssr_mode_axum (#575) 2023-03-21 17:12:34 -04:00
Greg Johnston
6b6782e8b0 fix: <Transition/> with local_resource (closes #562) (#574) 2023-03-21 17:12:34 -04:00
Markus Kohlhase
bf06b63779 example: Login with API token (CSR only) (#523) 2023-03-21 17:12:34 -04:00
Remo
409ffdd85f chore: macro panic hygiene (#568) 2023-03-21 17:12:34 -04:00
SleeplessOne1917
9bb5fc9965 fix: <Meta/> component as_ property outputs correct attribute html (#573) 2023-03-21 17:12:34 -04:00
Denis Nazarov
5a8039b68d Relax Eq to PartialEq for create_slice() (#570)
Co-authored-by: Denis Nazarov <denis.nazarov@gmail.com>
2023-03-21 17:12:34 -04:00
Greg Johnston
4c57ba4518 fixes issue #565 (#566) 2023-03-21 17:12:33 -04:00
Greg Johnston
ac6013efcc fix: transition fallback (closes #562) (#563) 2023-03-21 17:12:33 -04:00
Fangdun Tsai
3c3282887a feat: viz integration (#506) 2023-03-21 17:12:33 -04:00
PolarMutex
f829d6412e feature: add class prop to <Html/> component (#554) 2023-03-21 17:12:33 -04:00
Greg Johnston
bbafdbdb08 fix: issue with local resources blocking <Suspense/> fragments from resolving (#561) 2023-03-21 17:12:33 -04:00
Greg Johnston
f1d7ab0e75 fix: remove unnecessary log (#560) 2023-03-21 17:12:33 -04:00
Greg Johnston
98a4e87830 docs: add create_resource, <Suspense/>, and <Transition/> (#559) 2023-03-21 17:12:33 -04:00
Greg Johnston
4f524a57d8 docs: add example of <ButtonC on:click/> syntax (#558) 2023-03-21 17:12:33 -04:00
Thomas Versteeg
229b08084b doc: fix button name in parent_child example (#555) 2023-03-21 17:12:33 -04:00
Greg Johnston
d483d09300 v0.2.0-beta (#557) 2023-03-21 17:12:33 -04:00
Ben Wishovich
4a0e60ec42 fix issue with redirects in server fns creating multiple Location headers (#550) 2023-03-21 17:12:33 -04:00
Ikko Eltociear Ashimine
f0767cb76c fix: typo in hydration docs(#552)
identifer -> identifier
2023-03-21 17:12:33 -04:00
Chrislearn Young
0ca96d1bfe fix: document docs typo (#553) 2023-03-21 17:12:33 -04:00
Greg Johnston
8566725347 change: pass Scope as argument into Resource::read() and Resource::with() (#542) 2023-03-21 17:12:33 -04:00
Greg Johnston
2df349afd6 fix: more work on hydration IDs with <Suspense/> (#545) 2023-03-21 17:12:33 -04:00
Greg Johnston
7092bf5a6d revert PR #538 (#544) 2023-03-21 17:12:33 -04:00
Greg Johnston
26df094513 revert accident 2023-03-21 17:12:33 -04:00
Greg Johnston
3e95440b2d fix example 2023-03-21 17:12:33 -04:00
Dmitrii Kuzmin
bfa6cb0a78 fix(examples): hackernews_axum styles href (#536) 2023-03-21 17:12:33 -04:00
jquesada2016
149a377497 fix: off-by-one error in <For/> (closes #533) (#538) 2023-03-21 17:12:33 -04:00
Greg Johnston
6ae08493b3 fix: building leptos_reactive in release mode (#540) 2023-03-21 17:12:33 -04:00
Greg Johnston
858db3a792 v0.2.0-alpha2 (#539) 2023-03-21 17:12:33 -04:00
jquesada2016
10a2d27599 change: move signal method implementations into traits in signal prelude (#490) 2023-03-21 17:12:33 -04:00
Sean Aye
757f6231ef fix compile of leptos dom (#535) 2023-03-21 17:12:33 -04:00
Greg Johnston
042cf7614e feature: in-order streaming and async rendering (#496) 2023-03-21 17:12:33 -04:00
Greg Johnston
d8b02a1369 Fix test import location 2023-03-21 17:12:33 -04:00
Greg Johnston
427aa3f4c6 What's in a name? 2023-03-21 17:12:33 -04:00
Greg Johnston
b81592cf34 fix: hydration IDs for elements following <Suspense/> (closes #527) (#531) 2023-03-21 17:12:33 -04:00
Greg Johnston
a7d28e233b feature: reintroduce limited template-node cloning w/ template macro (#526) 2023-03-21 17:12:33 -04:00
Greg Johnston
7aed95b29b fix: top-level SVG in view macro with new exports (#525) 2023-03-21 17:12:33 -04:00
Greg Johnston
d90061f28e change: tweak API of Errors and implement IntoIter (#522) 2023-03-21 17:12:33 -04:00
henrik
d9cfcdad7c feature: enable cargo-leptos to reload multiple CSS files (#524) 2023-03-21 17:12:33 -04:00
Greg Johnston
dce7baaea0 Reexport web-sys event types in leptos::ev to make it easier to type handlers (#521) 2023-03-21 17:12:33 -04:00
Greg Johnston
f6145e8f65 fix: correct namespace for Unit in empty views (closes #518) (#520) 2023-03-21 17:12:33 -04:00
martin frances
7a93c3d3db leptos_dom erros.rs remove<E>() does not need to be generic. (#516)
* leptos_dom erros.rs remove<E>() does not need to be generic.

* fixed up errors.remove().
2023-03-21 17:12:33 -04:00
Greg Johnston
af4ae39a08 0.2.0-alpha (#515) 2023-03-21 17:12:33 -04:00
Greg Johnston
6ab2fef787 remove .unwrap() from redirect in Actix integration (#514) 2023-03-21 17:12:33 -04:00
IcosaHedron
0eaadaf391 do not unwrap use_context in integrations axum redirect (#513) 2023-03-21 17:12:33 -04:00
Greg Johnston
2a0ba3d884 CI: fix Wasm testing (#511) 2023-03-21 17:12:33 -04:00
Greg Johnston
02badcd23f fix: SSR export in Wasm mode (#512) 2023-03-21 17:12:33 -04:00
Greg Johnston
e4863bdba0 fix: import in leptos_dom and add Wasm build to CI for regressions (#510) 2023-03-21 17:12:33 -04:00
g-re-g
e601ab4949 Typos and a small cleanup (#509) 2023-03-21 17:12:33 -04:00
Greg Johnston
7362e1878a change: reorganize module exports and reexports (#503) 2023-03-21 17:12:33 -04:00
Greg Johnston
f8e84657b7 Add docs on testing (closes #489) (#508) 2023-03-21 17:12:33 -04:00
Greg Johnston
615ae14eec fix: <For/> in todomvc example (#504) 2023-03-21 17:12:33 -04:00
Greg Johnston
2f7c192835 docs: further additions (#505) 2023-03-21 17:12:33 -04:00
Greg Johnston
cbead2f02a apply new formatting everywhere (#502) 2023-03-21 17:12:33 -04:00
jquesada2016
517f4d423f chore: add workspace rustfmt.tml (#483) 2023-03-21 17:12:33 -04:00
Greg Johnston
7a88eae100 fix: proper disposal of nested route scopes (#499) 2023-03-21 17:12:33 -04:00
g-re-g
dbcfb023fc Allow literal string as class in view macro (#500) 2023-03-21 17:12:33 -04:00
Greg Johnston
10af646f37 examples: remove unused index.html (#497) 2023-03-21 17:12:33 -04:00
martin frances
03b7bd890a chore: remove unused .clone() call in <Suspense/>. (#486) 2023-03-21 17:12:33 -04:00
Greg Johnston
19985204c9 Handle <ErrorBoundary/> hydration correctly (closes #456) 2023-03-21 17:12:33 -04:00
Greg Johnston
c4364fa6d3 Correctly handle custom elements in SSR 2023-03-21 17:12:33 -04:00
Greg Johnston
2b6c8bbbfb Add error boundary example to list 2023-03-21 17:12:33 -04:00
Greg Johnston
ff67f64bcc Basic error boundary example 2023-03-21 17:12:33 -04:00
Greg Johnston
5a3bd9484c Update README.md 2023-03-21 17:12:33 -04:00
Greg Johnston
5c80182498 change: add Scope to view function in <For/> to avoid memory "leak" (#492) 2023-03-21 17:12:33 -04:00
Greg Johnston
475265acf8 missing ; 2023-03-21 17:12:33 -04:00
Greg Johnston
619260cf45 fix: fix debug_warn behavior in reactive crate and remove log dependency (#491) 2023-03-21 17:12:33 -04:00
jquesada2016
7e89eac267 change: NodeRef<HtmlElement<Div>> generics to NodeRef<Div> (#481) 2023-03-21 17:12:33 -04:00
Greg Johnston
17ee674b5c fix: typed route params with #[derive(Params)] (#488) 2023-03-21 17:12:33 -04:00
Greg Johnston
97ff7aa4f9 Fix inner_html in SSR (#487) 2023-03-21 17:12:33 -04:00
martin frances
3b0625f457 Minor: Clippy router now uses types OnFormData and OnResponse. (#484) 2023-03-21 17:12:33 -04:00
Greg Johnston
34c8a5b49a fix: errors on 404 page in axum_errors example (#485) 2023-03-21 17:12:33 -04:00
Jan
b51885e014 Better styling for router related components (#477) 2023-03-21 17:12:33 -04:00
Greg Johnston
4bc23f2828 remove unnecessary "openssl" feature from Actix examples (#480) 2023-03-21 17:12:33 -04:00
Greg Johnston
cca606527f Create README.md 2023-03-21 17:12:33 -04:00
Greg Johnston
93e0fc9379 docs: (in-progress) new tutorial/guide format with integrated CodeSandboxes (#375) 2023-03-21 17:12:33 -04:00
Greg Johnston
af0efa03ce Remove old book 2023-03-21 17:12:33 -04:00
Greg Johnston
24f4cecfbb fix: adding/removing errors from <ErrorBoundary/> (#478) 2023-03-21 17:12:33 -04:00
Greg Johnston
3d29fbc1ce fix: cargo doc in projects using #[server] (#476) 2023-03-21 17:12:33 -04:00
Greg Johnston
935d266f55 fix: correct out-of-order streaming behavior (#475) 2023-03-21 17:12:33 -04:00
g-re-g
b3369c6699 impl From<&str> for MaybeSignal<String> (#472) 2023-03-21 17:12:33 -04:00
Ben Wishovich
38a175a744 fix: convert site_address to site_addr to match cargo-leptos (#462) 2023-03-21 17:12:33 -04:00
Greg Johnston
edeb1dcf1e fix: fix node_ref in SSR (#471) 2023-03-21 17:12:33 -04:00
Greg Johnston
bd2baef127 fix: don't override element event listeners with component event listeners (closes #461) (#470) 2023-03-21 17:12:33 -04:00
Roland Fredenhagen
becf8a00cc error on non meta input for prop attribute (#469) 2023-03-21 17:12:33 -04:00
John Funk
b9a706a2bd Add simple icon logo (#468) 2023-03-21 17:12:33 -04:00
Greg Johnston
9ede00ca5d feature: add isomorphic <Redirect/> component (closes #412) (#466) 2023-03-21 17:12:33 -04:00
Roland Fredenhagen
381083121e impl Default for MaybeSignal (#464) 2023-03-21 17:12:33 -04:00
Greg Johnston
530f552616 docs: note about optional fallback (closes #406) (#463) 2023-03-21 17:12:33 -04:00
Jan
d092cdbaae Do it on an other branch (#460) 2023-03-21 17:12:33 -04:00
Greg Johnston
3fda12267f perf: further reduce WASM binary size by ~5-7% (#459)
* Update `leptos_router` docs
* Further reducing WASM bundle sizes
2023-03-21 17:12:33 -04:00
g-re-g
725954f784 Derive debug in server macro (#458) 2023-03-21 17:12:33 -04:00
Greg Johnston
4cb39d4bef docs: add new Children types to macro docs (#454) 2023-03-21 17:12:33 -04:00
Odiseo
c876cc9d65 fix: typo in leptos_config description (#455) 2023-03-21 17:12:33 -04:00
Greg Johnston
bc52e7e106 fix: stack overflow in with nested outlet (closes #452) (#453) 2023-03-21 17:12:33 -04:00
martin frances
0fc1ec1c94 Clippy: "{input} is not a supported environment. (#451) 2023-03-21 17:12:33 -04:00
Greg Johnston
eaf955b3ea fix: leptos_router hydration issues (#450) 2023-03-21 17:12:33 -04:00
Tobias Goulden Schultz
248a992ea2 fix: update leptos dependencies to point to the same workspace as other examples (#449) 2023-03-21 17:12:33 -04:00
Greg Johnston
35296b057f feature: allow on: event listeners on <Component/> nodes (#448) 2023-03-21 17:12:32 -04:00
Greg Johnston
850b129a0c fix: successfully pass context to nested routes via <Outlet/> (#447) 2023-03-21 17:12:32 -04:00
Gentle
fe3ce84200 use latest tokio in leptos_axum (#443) 2023-03-21 17:12:32 -04:00
martin frances
f7efd4d4ef router: Machete - Removed unused deps. (#442) 2023-03-21 17:12:32 -04:00
martin frances
d07d836ecb leptos_macro: Machete - Removed unused deps. (#441) 2023-03-21 17:12:32 -04:00
martin frances
b4a0fe85aa leptos-server: Removed dependecy on log, linear-map, rmp-serde. (#439) 2023-03-21 17:12:32 -04:00
g-re-g
bec11fead9 Dedup from_str implementations for Env (#426) 2023-03-21 17:12:32 -04:00
Greg Johnston
8eb60a2197 fix: correct behavior of <Show/> so it renders correctly when toggling between conditions multiple times, without rerendering on every change (#436) 2023-03-21 17:12:32 -04:00
Greg Johnston
21ddad1411 Fix top-level SVG elements in SSR (#435) 2023-03-21 17:12:32 -04:00
Greg Johnston
459fe54f55 Switch examples to check instead of build (for CI resources) and add missing examples (#437) 2023-03-21 17:12:32 -04:00
Greg Johnston
eb84f198af docs: Document inner_html attribute (#429) 2023-03-21 17:12:32 -04:00
Greg Johnston
b6bc7a070d Make RouteDefinition public (#430) 2023-03-21 17:12:32 -04:00
IcosaHedron
760a3574d0 Several Minor Updates on Examples (#427) 2023-03-21 17:12:32 -04:00
jquesada2016
a4c3292215 fixes cx not found on components marked with #[component(transparent)] (#423) 2023-03-21 17:12:32 -04:00
Greg Johnston
8670a36eeb fix: Make all fragment rendering lazy (closes #299 and #421) (#425)
Make all fragment rendering lazy (closes #299 and #421)
2023-03-21 17:12:32 -04:00
Greg Johnston
e5adb2ef0c fix: HTML entity issues in axum_errors example (#424) 2023-03-21 17:12:32 -04:00
Ben Wishovich
0378e0b077 Update ErrorBoundary to use miette::Diagnostic instead of Error, and various other tweaks (#401)
* Switch RwLock to parking_lot so they are no longer async
* cleanup todo_app_sqlite_axum
* add errors_axum example

---------

Co-authored-by: Indrazar <110272232+Indrazar@users.noreply.github.com>
2023-03-21 17:12:32 -04:00
starmaker
7301a24918 Implemented update_returning for StoredValue (#419) 2023-03-21 17:12:32 -04:00
Greg Johnston
f15f2365ac Fix issues with attribute names in SSR (#418) 2023-03-21 17:12:32 -04:00
Bruno De Simone
910aa6d993 Add leptos_routes functions for integrations (#415)
* added leptos_routes_with_context

* added leptos_routes_with_handler for axum integration
2023-03-21 17:12:32 -04:00
Ben Wishovich
9c9218c346 Switch RwLock to parking_lot so they are no longer async (#414) 2023-03-21 17:12:32 -04:00
Greg Johnston
9c55b35f6a Fix <option> and <use> top-level types in SSR (#416) 2023-03-21 17:12:32 -04:00
martin frances
05b1ce50d9 Escape <HTML> and <BODY> tokens in documentation markup. (#410) 2023-03-21 17:12:32 -04:00
martin frances
ed4815dd0e Minor: Bump typed-builder from 0.11 to 0.12. (#409) 2023-03-21 17:12:32 -04:00
Greg Johnston
db3c041e2f Add <Html/> and <Body/> components in leptos_meta (#407)
Closes #376.
2023-03-21 17:12:32 -04:00
Greg Johnston
d7c5cd8f27 oops 2023-03-21 17:12:32 -04:00
Greg Johnston
1c235e75df escape attributes 2023-03-21 17:12:32 -04:00
Greg Johnston
5c2381c675 Fixes boolean attributes in SSR (closes #405) 2023-03-21 17:12:32 -04:00
Greg Johnston
0e0fbf43f4 Revert "fix: Fixes boolean attributes in HTML fast-path (closes issue #405)"
This reverts commit 2ecb345a79.
2023-03-21 17:12:32 -04:00
Greg Johnston
0952dcd2d3 fix: Fixes boolean attributes in HTML fast-path (closes issue #405) 2023-03-21 17:12:32 -04:00
Greg Johnston
78d884db00 Add Children type alias 2023-03-21 17:12:32 -04:00
Greg Johnston
c8ff557a1c Fix labels in parent_child README 2023-03-21 17:12:32 -04:00
Greg Johnston
5e469039eb 0.1.3 2023-03-21 17:12:32 -04:00
Greg Johnston
00782697ef Missing web-sys types 2023-03-21 17:12:32 -04:00
Greg Johnston
6ad325fc6b Fix <ErrorBoundary/> removal behavior 2023-03-21 17:12:32 -04:00
Greg Johnston
a16becddcd Docs for <Show/> component 2023-03-21 17:12:32 -04:00
Greg Johnston
487a87ce49 Docs for <ErrorBoundary/> 2023-03-21 17:12:32 -04:00
Greg Johnston
e7184ee3f3 Fix hydration issue related to WASM size reduction 2023-03-21 17:12:32 -04:00
Greg Johnston
f46106e606 cargo fmt 2023-03-21 17:12:32 -04:00
Greg Johnston
1f5f8c03c2 clippy stuff 2023-03-21 17:12:32 -04:00
Greg Johnston
2a4c3f00d8 Make helpers into concrete functions for WASM binary size purposes 2023-03-21 17:12:32 -04:00
Greg Johnston
12affc3d98 Use a concrete helper function to generate elements 2023-03-21 17:12:32 -04:00
Thomas Queiroz
d923bf868a Fix gtk example 2023-03-21 17:12:32 -04:00
Greg Johnston
301e4d8288 Missing Storage dependency (now that gloo is gone) 2023-03-21 17:12:32 -04:00
Greg Johnston
fd2a074693 Remove gloo dependency in leptos_dom 2023-03-21 17:12:32 -04:00
Martin
9416517e0e BugFix, ch03 properly construct the "input_element". 2023-03-21 17:12:32 -04:00
Martin
b5a9131c8e doc/book updated leptos version. 2023-03-21 17:12:32 -04:00
Greg Johnston
a8d6b9aca3 Correctly set pending state with ActionForm 2023-03-21 17:12:32 -04:00
Greg Johnston
8db98f26d2 ActionForm should clear input as Action::dispatch() does 2023-03-21 17:12:32 -04:00
Greg Johnston
50eff91072 Fix missing docs error (#389) 2023-03-21 17:12:32 -04:00
Greg Johnston
7d6e3c99bc Check uniqueness of server function names at registration time (#388)
* Check uniqueness of server function names at registration time, and stop leaking src file path in release mode

* Fix missing dev-dependency
2023-03-21 17:12:32 -04:00
Greg Johnston
283dfdd075 Fix a large number of small issues in docs (#386)
* Fix example links in docs

* Restore missing CSR READMEs

* Document need to enable features on `leptos_router` and `leptos_meta`

* Add "Is it production ready?" to FAQs

* Document which types are provided as contexts in server integrations

* Fix broken links and other issues in docs
2023-03-21 17:12:32 -04:00
Greg Johnston
eaeca26d12 Allow unused cx in server fn arguments (#385)
* Suppress warning for unused `cx` in server function arguments
2023-03-21 17:12:32 -04:00
Greg Johnston
c939182c68 implements From<Signal<T>> for MaybeSignal<T> (#384) 2023-03-21 17:12:32 -04:00
Greg Johnston
a496f3c5a9 Replace site-address with site-addr in cargo-leptos example Cargo.toml files 2023-03-21 17:12:32 -04:00
Gentle
b6a8171f4c leptos_axum::handle_server_fns was also duplicated (#383) 2023-03-21 17:12:32 -04:00
Roland Fredenhagen
aff190d41b added hgroup element (#379) 2023-03-21 17:12:32 -04:00
Gentle
88e98c0f7e cloning is not needed here (#381) 2023-03-21 17:12:32 -04:00
Gentle
ac92b63e4c refactor to eliminate duplicate code (#380) 2023-03-21 17:12:32 -04:00
Greg Johnston
5b116596bf Fix context in outlets (#374)
* Add `Scope::parent()` to make access to parent `Scope` possible.

* Handle context properly in nested routes
2023-03-21 17:12:32 -04:00
Markus Kohlhase
8e2d5598b5 Add a counter example that does not use macros (#373) 2023-03-21 17:12:32 -04:00
Ben Wishovich
4023e16507 Make Errors Sync (#372) 2023-03-21 17:12:32 -04:00
IcosaHedron
d4da935a0c Fix CSR with Trunk on hackernews example, remove CSR option from isomorphic example (#369)
* Fix CSR with Trunk on hackernews example

* Update isomorphic example to remove CSR from Readme
2023-03-21 17:12:32 -04:00
Markus Kohlhase
1d5ed41e1d Replace urlencoding with percent-encoding (#365)
Motivation: `percent-encoding` is from the Servo team and part of the `url` crate.
2023-03-21 17:12:32 -04:00
Ben Wishovich
22b8640b37 Add <Show/> component to avoid rerendering of closures and tweak ErrorBoundary (#363)
Add once_cell to leptos, and add Show component! Modify ErrorBoundary to
take a closure that implements IntoView, not View
2023-03-21 17:12:32 -04:00
Greg Johnston
e5998eb321 Reorganize docs re: snake-case names 2023-01-23 09:09:35 -05:00
Greg Johnston
65b0e1265b clippy 2023-01-23 09:09:26 -05:00
Ben Wishovich
9b0fb63632 Add methods to take Actix/Axum Extractors/Route Info/Stuff and pass it to Leptos (#359) 2023-01-23 07:28:05 -05:00
Greg Johnston
2febaf6b99 Merge pull request #358 from martinfrances107/bump_base64
leptos_reactive base64 bump version to 0.21.
2023-01-23 07:27:01 -05:00
Greg Johnston
6c8e8e9ce7 Merge pull request #353 from martinfrances107/redundant_clone
Clippy fixes: redundant clone and .to_string() issues.
2023-01-23 07:26:50 -05:00
Martin
7aa0181192 Removed unused variables. 2023-01-23 09:46:28 +00:00
Martin
8496bd59ce leptos_reactive base64 bump version to 0.21. 2023-01-22 22:15:54 +00:00
Greg Johnston
fd6e63796e Merge pull request #354 from jclmnop/feat/allow-snake-case-components
Allow snake case components
2023-01-22 16:46:47 -05:00
jclmnop
39cddfc82d update docs for component macro 2023-01-22 17:13:24 +00:00
jclmnop
d1333a3402 modify component attribute macro to allow snake_case fn names 2023-01-22 14:04:36 +00:00
Martin
7f9919e2d5 Clippy fixes: redundant clone, .to_string() issues. 2023-01-22 14:03:15 +00:00
Greg Johnston
fc2d6ef19d Merge pull request #343 from killertux/fix/fix-query-params-parser 2023-01-21 17:23:39 -05:00
Greg Johnston
a5531b1a7c Merge pull request #338 from benwis/error-handling
ErrorBoundary Component
2023-01-21 16:03:48 -05:00
benwis
81ab77e8ea One more time! 2023-01-21 11:54:55 -08:00
benwis
23bd399239 I did, I did break it 2023-01-21 11:25:36 -08:00
benwis
3e04318082 Remove extra 2023-01-21 10:58:47 -08:00
benwis
2d88524354 Wrap cfg_if to prevent on_cleanup from panicing on the server 2023-01-21 10:56:38 -08:00
Greg Johnston
ecb784e422 Merge pull request #352 from leptos-rs/gbj-patch-1
Update html.rs
2023-01-21 13:07:07 -05:00
Greg Johnston
69e02bfce2 Update html.rs
Yikes! Fix broken format string.
2023-01-21 13:07:00 -05:00
Greg Johnston
a75abb9e04 Merge pull request #351 from leptos-rs/view-styling
Add support for `class = ...`, in `view` macro to support scoped styling
2023-01-21 12:56:21 -05:00
Greg Johnston
bf1ef1b7c2 Fix missing {} after cleaning up unnecessary formats 2023-01-21 11:42:52 -05:00
Greg Johnston
7fb7bb90f8 Merge pull request #350 from leptos-rs/fix-script
Add SVG `<script>`, `<style>`, and `<title>` to set of ambiguous elements
2023-01-21 09:52:53 -05:00
Greg Johnston
a22a693de7 Add support for class = ..., in view macro to support scoped styling solutions 2023-01-21 09:52:05 -05:00
Clemente
cbb1e4c9d2 Update docs 2023-01-21 11:19:28 -03:00
Clemente
dbccf525ac Added some tests 2023-01-21 11:17:25 -03:00
Greg Johnston
ed6d6ae4b0 Add node_ref to docs 2023-01-21 07:26:06 -05:00
Greg Johnston
89ee88d75e Add SVG <script>, <style>, and <title> to set of ambiguous elements — closes #349 2023-01-21 07:23:32 -05:00
benwis
9ea604f516 Merge branch 'main' into error-handling 2023-01-20 15:53:18 -08:00
benwis
b5ab7b107a Test of SSR/Hydration of ErrorBoundary 2023-01-20 15:52:43 -08:00
Clemente
18eecd9606 Use URLSearchParams to handle client side query param logic 2023-01-20 18:11:49 -03:00
Greg Johnston
a49dfd3f8e Merge pull request #344 from leptos-rs/view-ssr
Reenable optimizations for SSR using the `view!` macro
2023-01-20 15:14:06 -05:00
Greg Johnston
7075f58451 Merge pull request #347 from imalexlab/doc/add-port-leptos-watch
doc: add link for leptos watch
2023-01-20 14:29:19 -05:00
Kompreni
bcabdddce5 doc: add link for leptos watch 2023-01-20 20:14:09 +01:00
Greg Johnston
726393c446 Fix SSR tests 2023-01-20 13:45:23 -05:00
Greg Johnston
c336eb8769 0.1.1 2023-01-20 13:24:05 -05:00
Greg Johnston
0f5f0de410 Merge pull request #346 from leptos-rs/suspense-comments
Change `<Suspense/>` to a specialized type that uses comments for SSR
2023-01-20 13:18:41 -05:00
Greg Johnston
3d769c9f21 Clean up some rendering issues and the panic when cleaning up 2023-01-20 13:14:09 -05:00
Greg Johnston
9ac0f0a579 Fix todomvc 2023-01-20 12:18:31 -05:00
Greg Johnston
a385f502b6 Merge pull request #345 from leptos-rs/provide-route-contexts-when-equal
Fix behavior of `RouteContext` in nested routes with different parameters
2023-01-20 12:13:43 -05:00
Greg Johnston
603eead12d cargo fmt 2023-01-20 12:06:04 -05:00
Greg Johnston
8a73f3b879 Use comment nodes for <Suspense/> to avoid both hydration and styling issues 2023-01-20 12:05:21 -05:00
Greg Johnston
5fc8907b85 Remove extraneous log 2023-01-20 10:37:14 -05:00
Greg Johnston
678990194f Update RouteContext.path() value when params change but route has not change (closes #340) 2023-01-20 10:36:48 -05:00
Greg Johnston
a964e89d1a cargo fmt 2023-01-20 10:08:13 -05:00
Greg Johnston
285092a467 Reenable SSR benchmarks 2023-01-20 10:00:16 -05:00
Greg Johnston
c1c74ead0f Get view-macro SSR optimization working 2023-01-20 09:47:16 -05:00
Clemente
e4c9109278 Fix query params behaviour difference between SSR and Hydrate 2023-01-20 09:13:18 -03:00
benwis
64add54de6 Add example error template and give the ability to access error info
inside it
2023-01-19 14:57:34 -08:00
benwis
ac343427e7 Remember all the files 2023-01-18 23:21:08 -08:00
benwis
452e397048 Made todo_app_sqlite_axum throw an error 2023-01-18 16:47:22 -08:00
benwis
ad3ac5ad3c Remove silly thing 2023-01-18 16:03:53 -08:00
benwis
db63eda2f5 Push gbj's updates 2023-01-18 16:02:06 -08:00
benwis
6cbdc57f7a Add working impl of ErrorBoundary 2023-01-18 15:49:42 -08:00
benwis
3215e44c9a Create example of file_and_error handler for Axum, and create <ErrorBoundary/>
for leptos
2023-01-18 12:59:15 -08:00
Greg Johnston
b54a60213b Merge pull request #333 from leptos-rs/minimize-runtime-panics
Minimize panics when runtime has already been disposed (e.g., in SSR)
2023-01-17 22:48:42 -05:00
Greg Johnston
ebeb1d69d1 Merge pull request #334 from leptos-rs/debug-meta
Fix `MetaContext` debug for wasm target
2023-01-17 14:23:41 -05:00
Greg Johnston
cadb04b076 Fix MetaContext debug for wasm target 2023-01-17 14:23:13 -05:00
Greg Johnston
490b7a1596 Merge pull request #332 from leptos-rs/programmatic-navigation-in-router-example
Add programmatic navigation in router example
2023-01-17 13:54:58 -05:00
Greg Johnston
f4d781e739 Merge pull request #331 from benwis/main
Path and Query for Axum
2023-01-17 13:54:49 -05:00
Greg Johnston
ebe5bf4600 Merge pull request #330 from martinfrances107/typed_builder
typed-builder inconsistent version.
2023-01-17 13:53:58 -05:00
Greg Johnston
d62046dc6f Merge pull request #329 from leptos-rs/meta-context-debug
impl `Debug` on `MetaContext`
2023-01-17 13:53:24 -05:00
Greg Johnston
c7abb57168 Merge pull request #328 from martinfrances107/crate_io_readme_issue
Minor: For each sub crate the landing page should be the root README.md.
2023-01-17 13:53:14 -05:00
Greg Johnston
bc0cd5d0ba Minimize panics when runtime has already been disposed (e.g., in streaming SSR) 2023-01-17 13:11:35 -05:00
Greg Johnston
7df67444f9 cargo fmt fix 2023-01-17 12:45:59 -05:00
Greg Johnston
40155e91ea cargo fmt fix 2023-01-17 12:43:27 -05:00
Greg Johnston
5c062fa6f1 Add use_navigate in router example 2023-01-17 12:40:54 -05:00
Greg Johnston
3517820afd Restore missing docs on <A/> component 2023-01-17 12:40:23 -05:00
benwis
300cc4f54c Actually Do It 2023-01-17 09:27:09 -08:00
Martin
586e9be99a Minor - type-builder version is inconsistent. 2023-01-17 17:23:05 +00:00
Greg Johnston
6ed86d0ee9 impl Debug on MetaContext 2023-01-17 12:17:16 -05:00
Martin
1fe93fd588 Minor: For each sub crate the landing page should be the root README.md. 2023-01-17 17:05:09 +00:00
Greg Johnston
2723871a80 Merge pull request #327 from ekanna/main
Updated example code and README to use latest syntax for data binding
2023-01-17 11:56:59 -05:00
benwis
70d92c7f42 Path and Query 2023-01-17 05:52:38 -08:00
Greg Johnston
e96d4b0687 Merge pull request #326 from benwis/main
Make sure Axum returns a relative URI for http and https requests
2023-01-17 06:34:04 -05:00
ekanna
ce0910caca Updated example code and README to use latest syntax for data binding 2023-01-17 12:08:44 +05:30
benwis
81a937277d Simplify URI matching solution 2023-01-16 22:35:22 -08:00
benwis
355e711964 Fix issue with https pathing for Axum integration 2023-01-16 22:18:39 -08:00
Greg Johnston
27ec506fd5 Merge pull request #321 from leptos-rs/for-ssr 2023-01-16 21:49:24 -05:00
Greg Johnston
79c76ae4cb Merge pull request #324 from leptos-rs/fix-fallback
Fix `<Router fallback>` (signature and functionality)
2023-01-16 20:51:01 -05:00
Greg Johnston
e416815591 clippy warning 2023-01-16 20:08:27 -05:00
Greg Johnston
81bdd6788f Fix hydration in release mode if _0-0-0 is a marker, not an element 2023-01-16 20:08:07 -05:00
Greg Johnston
f7d5567a35 Fix fallback (signature and functionality) 2023-01-16 19:55:32 -05:00
Greg Johnston
ae0a243cc0 Fix meta doctests 2023-01-16 12:08:13 -05:00
Greg Johnston
7893ff8b55 Fix SSR doctests 2023-01-16 10:36:18 -05:00
Greg Johnston
6130e708ce cargo fmt 2023-01-16 09:26:40 -05:00
Greg Johnston
d049d2f36b Use comments instead of element markers for hydration -- fixes issue #320 2023-01-16 09:21:28 -05:00
Greg Johnston
61ca6465df Merge pull request #318 from benwis/main
Switch get_configuration calls to None and add a note in the docs for get_configuration()
2023-01-16 07:23:55 -05:00
benwis
10a833d763 Switch get_configuration calls to None and add a note in the docs for
uses of get_configuration()
2023-01-15 12:50:25 -08:00
Greg Johnston
17982e8ac5 Merge pull request #316 from leptos-rs/death-to-suspense-hydration-mismatches
Death to suspense hydration mismatches
2023-01-14 15:19:12 -05:00
Greg Johnston
6cfb6227f5 Merge pull request #315 from leptos-rs/add-code-of-conduct-1
Create CODE_OF_CONDUCT.md
2023-01-14 14:14:29 -05:00
Greg Johnston
159852b8d7 clippy 2023-01-14 14:12:52 -05:00
Greg Johnston
6f95713b59 Fix <Suspense/> hydration 2023-01-14 14:10:19 -05:00
Greg Johnston
e17afd4559 Handle custom elements correctly 2023-01-14 14:09:23 -05:00
Greg Johnston
e0aa1e245b Create CODE_OF_CONDUCT.md 2023-01-14 12:04:11 -05:00
Greg Johnston
7951a6e9cf Merge pull request #314 from leptos-rs/create-slice-doctest
Fix doctest in `create_slice` and edit doc comment slightly
2023-01-14 09:50:29 -05:00
Greg Johnston
1f39299303 Fix doctest in create_slice and edit doc comment slightly 2023-01-14 08:17:27 -05:00
Greg Johnston
2be4610233 Update README.md 2023-01-14 08:03:57 -05:00
Greg Johnston
af254e9b61 Merge pull request #312 from TaKO8Ki/use-rust-cache
Use rust-cache in CI
2023-01-14 07:59:18 -05:00
Takayuki Maeda
4aae8a5088 use rust cache 2023-01-14 20:07:09 +09:00
Greg Johnston
7ff044cef6 Merge pull request #308 from Indrazar/main
Update Generated API URL on Windows Attempt #2
2023-01-13 07:30:03 -05:00
Greg Johnston
11122b575e Merge pull request #310 from akesson/doc-examples-fixes
Doc fix + search & replace url
2023-01-13 07:29:47 -05:00
Greg Johnston
a62ee4031b Merge branch 'main' into doc-examples-fixes 2023-01-13 07:29:42 -05:00
Greg Johnston
19b43607a1 Merge pull request #309 from dzfrias/patch-1 2023-01-13 07:27:46 -05:00
hakesson
884297706a Search https://github.com/gbj/ and replace with https://github.com/leptos-rs/ 2023-01-13 09:03:11 +01:00
hakesson
fb4c208609 Should point to counters (plural) 2023-01-13 09:00:35 +01:00
Diego Frias
5701e74efb Fix link to counters_stable in README 2023-01-12 20:26:11 -08:00
indrazar
2afe8e202a update url for Windows directories attempt 2 2023-01-12 22:07:55 -05:00
Greg Johnston
08ec473304 Merge pull request #296 from Gentle/create_slice
create_slice in leptos_reactive
2023-01-12 13:26:51 -05:00
Greg Johnston
3ae0880db4 Merge pull request #305 from leptos-rs/0.1.0
Version `0.1.0` release
2023-01-12 12:53:26 -05:00
Ramon Klass
9180aaad7e create_slice: actual documentation 2023-01-12 16:51:37 +01:00
Ramon Klass
89be6bc68e removed Debug from create_slice 2023-01-12 16:30:56 +01:00
Ramon Klass
56426170b0 remove Debug from create_memo 2023-01-12 16:30:56 +01:00
Ramon Klass
0571ea4103 create_slice for RwSignal with 2 closures 2023-01-12 16:30:56 +01:00
Greg Johnston
cdf709fb09 0.1.0 2023-01-12 09:57:08 -05:00
Greg Johnston
7eaa36812d Merge pull request #301 from leptos-rs/ssr-inner-html
Fix SSR of elements with `inner_html`
2023-01-11 21:59:45 -05:00
Greg Johnston
2ef36c65fd cargo fmt 2023-01-11 20:58:26 -05:00
Greg Johnston
a16540ccc5 Merge pull request #302 from martinfrances107/invalid_toml
Minor: "leptos.workspace = true" is invalid.
2023-01-11 20:48:51 -05:00
Greg Johnston
613c7b32a1 Merge pull request #300 from akesson/pre-resolved-data 2023-01-11 13:03:39 -05:00
Martin
8f2a731c9f Minor formatting fix. 2023-01-11 17:44:56 +00:00
Martin
1621b86d8f Minor: "leptos.workspace = true" is invalid. 2023-01-11 17:09:10 +00:00
Greg Johnston
b1ac17995d Fix SSR of elements with inner_html 2023-01-11 07:47:24 -05:00
hakesson
6471af8b89 Let data_fn return DataResponse 2023-01-11 12:08:44 +01:00
hakesson
abf54b832e Improve naming and doc 2023-01-11 09:56:58 +01:00
hakesson
91e839c71a data_fn returns Result 2023-01-11 09:08:07 +01:00
Greg Johnston
b944b17e6d Update Leptos_logo_pref_dark_RGB.svg 2023-01-10 21:56:30 -05:00
Greg Johnston
54c1abb4b7 Merge pull request #298 from leptos-rs/dark-mode-logo
Dark mode logo
2023-01-10 21:52:15 -05:00
Greg Johnston
c24f33aeb2 Dark-mode logo 2023-01-10 21:51:59 -05:00
Greg Johnston
9e83acfe63 Make cargo fmt happy 2023-01-10 21:18:03 -05:00
Greg Johnston
46254a18f3 Improve router feature warning 2023-01-10 21:10:27 -05:00
Greg Johnston
7d7a96d9bc Switch logo on color-scheme change 2023-01-10 13:51:52 -05:00
hakesson
339c920b19 Make data_fn take cloned HttpRequest 2023-01-10 18:55:45 +01:00
Greg Johnston
ecc24fa65d Create FUNDING.yml
Add GitHub sponsor info
2023-01-10 12:52:39 -05:00
hakesson
3f036ee321 Fix refactoring error 2023-01-10 18:48:05 +01:00
hakesson
4e00ec2348 Add leptos_data_routes 2023-01-10 18:27:35 +01:00
hakesson
9c59b720b7 Improve fmt 2023-01-10 18:26:11 +01:00
hakesson
da4340894f Extract fn provide_contexts 2023-01-10 18:18:25 +01:00
hakesson
02f5c3891c Extract fn leptos_corrected_path 2023-01-10 18:06:24 +01:00
hakesson
087e67466f Extract fn html_parts & stream_app 2023-01-10 18:03:11 +01:00
Greg Johnston
1925c5bbe5 Merge pull request #294 from martinfrances107/workflow_cargo_fmt
Policy change ( part 2 ) Added rule of enforcing cargo fmt.
2023-01-10 09:37:38 -05:00
Greg Johnston
1613616008 Merge branch 'main' into workflow_cargo_fmt 2023-01-10 09:36:53 -05:00
Greg Johnston
8a01880ade Merge pull request #293 from benwis/remove-deps
Remove a couple extra deps from the axum integration
2023-01-10 09:36:15 -05:00
Greg Johnston
180ab87ff9 Merge pull request #282 from akesson/workspace-multi-projects
Use envs for workspace config
2023-01-10 09:35:41 -05:00
hakesson
e324fb6e76 Default site-root to '.' 2023-01-10 10:33:53 +01:00
hakesson
0547b4f846 Add missing semi-colon 2023-01-10 10:01:23 +01:00
henrik
75659ce674 Merge branch 'main' into workspace-multi-projects 2023-01-10 09:59:44 +01:00
Martin
190cb162ad Added rustfmt to setup for actions-rs/toolchain. 2023-01-10 08:52:55 +00:00
hakesson
1f556cefb0 Default to serve root 2023-01-10 09:52:21 +01:00
hakesson
6a68ef67f3 Add LEPTOS prefix to OUTPUT_NAME in all files 2023-01-10 09:26:10 +01:00
Martin
23bbd90c81 Policy change ( part 2 ) added rule of enforcing cargo fmt. 2023-01-10 08:20:02 +00:00
benwis
27b8553076 Remove a couple extra deps from the axum integration 2023-01-09 23:46:07 -08:00
hakesson
5bfeb93e3d Make Cargo.toml optional 2023-01-10 08:26:22 +01:00
hakesson
dd9ae1b7b1 Add LEPTOS prefix to OUTPUT_NAME 2023-01-10 08:25:43 +01:00
Greg Johnston
ad34a5d9c6 Update name to leptos-rs/leptos 2023-01-09 21:59:13 -05:00
Greg Johnston
ace5e7cbba Add missing hackernews_axum makefile 2023-01-09 21:59:00 -05:00
Greg Johnston
c8f0988e53 Merge pull request #292 from gbj/router-warnings
Implement `state` and `replace` correctly in `leptos_router` and clear warnings
2023-01-09 21:11:28 -05:00
Greg Johnston
64f0f8879b Implement state and replace correctly in leptos_router and clear warnings 2023-01-09 21:10:42 -05:00
Greg Johnston
b8cafeb650 Merge pull request #289 from gbj/forbid-unsafe
Forbid `unsafe` code in all packages
2023-01-09 20:45:28 -05:00
Greg Johnston
992b218ffe Merge pull request #291 from gbj/correct-axum-query-handling
Correct Axum query handling
2023-01-09 20:44:58 -05:00
Greg Johnston
5df89b0d25 Fix query parsing in Axum integration 2023-01-09 20:44:06 -05:00
Greg Johnston
c050456a47 Use a runtime warning about SVG <a/> instead of a macro warning on all ambiguous tags 2023-01-09 20:31:51 -05:00
Greg Johnston
8a8d7cbe1b Fix forbid_unsafe in a frustratingly-stupid way 2023-01-09 20:07:16 -05:00
Greg Johnston
f5f345e623 Merge pull request #286 from benwis/favicons
FAVICON!
2023-01-09 19:57:27 -05:00
Greg Johnston
4df3687463 Forbid unsafe code in all packages 2023-01-09 19:48:51 -05:00
Greg Johnston
f6622448e9 Update README.md 2023-01-09 19:38:02 -05:00
Greg Johnston
78825401c5 Merge pull request #288 from gbj/new-logo
New logo
2023-01-09 19:34:10 -05:00
Greg Johnston
f2b7ad6244 New logo 2023-01-09 19:33:44 -05:00
Greg Johnston
43f107d9bd New logo 2023-01-09 19:33:38 -05:00
Greg Johnston
a2612ca1fc Merge pull request #275 from martinfrances107/cargo_fmt
Policy change: Workflow now enforce "cargo fmt".
2023-01-09 19:20:57 -05:00
Greg Johnston
a000c84e1a Fix scope disposal code in Router (closes issue #240) 2023-01-09 19:17:37 -05:00
benwis
ee647cba1c Add Favicons to all the examples and standardize on the public folder for public assets 2023-01-09 15:27:52 -08:00
Greg Johnston
1377b823e2 Merge pull request #285 from martinfrances107/version_numbers
simple_logger use version 4.0.0 everywhere.
2023-01-09 18:26:57 -05:00
Martin
4d21f5ac63 simple_logger use version 4.0.0 everywhere. 2023-01-09 21:43:48 +00:00
hakesson
1ec603ee58 Use envs for workspace config 2023-01-09 20:06:43 +01:00
Martin
c56806713e Keeping up with changes to main. 2023-01-09 12:47:50 +00:00
Martin
2f6aa6753d Removed workflow "Cargo fmt" test. 2023-01-09 12:44:35 +00:00
Martin
2544687acd Moved the order of check. 2023-01-09 12:44:35 +00:00
Martin
3d25e86c23 Policy change: Workflow now enforce "cargo fmt". 2023-01-09 12:44:30 +00:00
Greg Johnston
28ec3a6cda Merge pull request #281 from martinfrances107/hackernews_axum
Minor: Clippy fixes related to hackernew_axum.
2023-01-09 07:02:43 -05:00
Greg Johnston
8b92a561a3 Merge pull request #269 from benwis/generated_routes
Generate Routes and pass them to Actix/Axum
2023-01-09 07:02:11 -05:00
Martin
e490c0423f Minor: Clippy fixes related to hackernew_axum. 2023-01-09 09:54:39 +00:00
benwis
b6579a040a Warning Squashing 2023-01-08 19:41:22 -08:00
benwis
01e024b726 One more time! 2023-01-08 19:38:45 -08:00
benwis
6603c44ce2 Minor fixes and revisions 2023-01-08 19:36:24 -08:00
Greg Johnston
977f11b180 Merge pull request #280 from gbj/prevent-panic-in-ssr
Closes #278: Prevent `create_signal_from_stream` from panicking on SSR
2023-01-08 19:52:48 -05:00
Greg Johnston
fb34b29ccf Merge pull request #279 from DPM97/default_prop_values
default prop values in prop macro
2023-01-08 19:52:38 -05:00
benwis
6576d8eda1 Change site_root default to ".". Hope that cargo-leptos has that check 2023-01-08 14:54:32 -08:00
benwis
6b729f9131 Fix hackernews_axum example 2023-01-08 14:51:41 -08:00
benwis
dc60c35b58 Rewrite file handlers for Axum, and update all examples to use the new
generated routes. Fix a few issues in the integrations, and reduce the
number of warnings
2023-01-08 14:18:51 -08:00
Greg Johnston
32ec9cc57e Prevent create_signal_from_stream from panicking on SSR 2023-01-08 17:09:04 -05:00
Dylan Maloy
35601d8284 update abort_opt_message 2023-01-08 16:47:02 -05:00
Dylan Maloy
49bc7d2a27 init 2023-01-08 16:35:43 -05:00
Greg Johnston
aa7c7367dc Merge pull request #277 from martinfrances107/clippy_hackernews
examples/hackernews - Cargo clippy fixes.
2023-01-08 14:10:57 -05:00
Greg Johnston
70808c5262 Merge pull request #272 from DPM97/component_lifetimes
fix component macro lifetime parsing
2023-01-08 14:07:00 -05:00
Martin
67503a108d BugFix. 2023-01-08 15:28:30 +00:00
Martin
ef52a01838 examples/hackernews - Cargo clippy fixes. 2023-01-08 13:33:53 +00:00
Greg Johnston
4cacfe98d8 Merge pull request #273 from martinfrances107/needless_borrow
Minor: Removed Clippy::needless_borrrow issues.
2023-01-08 07:27:02 -05:00
Greg Johnston
52e653316e Merge pull request #270 from gbj/chorse
Chores
2023-01-08 07:26:14 -05:00
Greg Johnston
bf5b6ca9c2 Merge pull request #264 from martinfrances107/Clipp_removed_clone_round_2
Removing clone call where possible(round2).
2023-01-08 07:26:00 -05:00
Martin
8875939a27 Minor: Removed Clippy::needless_borrrow issues. 2023-01-08 10:42:25 +00:00
Martin
b9a83277d9 Removing clone call where possible(round2). 2023-01-08 09:57:19 +00:00
benwis
dad84b5867 Merge branch 'main' into generated_routes 2023-01-07 21:17:18 -08:00
Dylan Maloy
1f29d29947 init 2023-01-08 00:15:00 -05:00
benwis
1b8175e2fa Add missing tokio dep for RwLock 2023-01-07 20:27:05 -08:00
Greg Johnston
dbe3ec015c Fix warning for unused variable. 2023-01-07 22:06:02 -05:00
Greg Johnston
492fa6c6d3 Fix link to Stream in docs. 2023-01-07 22:05:44 -05:00
Greg Johnston
343e8c8abe Update macro docs to reflect newly-available class syntax. 2023-01-07 22:02:23 -05:00
Greg Johnston
656d20cb65 Don't panic in proc macro, use proc_macro_error instead. 2023-01-07 21:32:52 -05:00
Greg Johnston
a0a66b75dd Allow complex class names with ("class-[name]-42", value) syntax. 2023-01-07 21:29:26 -05:00
Greg Johnston
085ba3506c Merge pull request #267 from gbj/adjust-tracing
Adjust tracing
2023-01-07 20:31:54 -05:00
Greg Johnston
63f3780eda Merge pull request #268 from gbj/fnonce-children
`children` should take `FnOnce(Scope) -> Fragment`, to ease need of c…
2023-01-07 20:31:29 -05:00
benwis
c41cf879d1 Formatting 2023-01-07 15:44:35 -08:00
benwis
b34f2070d3 Remove extraneous route 2023-01-07 15:09:49 -08:00
benwis
7fa21defa6 Merge remote-tracking branch 'origin/generated_routes' into generated_routes 2023-01-07 15:08:12 -08:00
benwis
bdd9abc04d Removing some missed code and changing the stylesheet 2023-01-07 15:06:21 -08:00
Ben Wishovich
1d25134213 Merge branch 'main' into generated_routes 2023-01-07 14:58:26 -08:00
benwis
de73622949 Change Axum's "" matching 2023-01-07 14:53:38 -08:00
benwis
5d3cfc6483 Actix seems to be working now, plus applied Henrik's path recommendations 2023-01-07 14:49:25 -08:00
Greg Johnston
6fbbd09000 <Suspense/> and <Transition/> should take Fn for children because they need to use it multiple times 2023-01-07 17:09:50 -05:00
Greg Johnston
f2842cf14e children should take FnOnce(Scope) -> Fragment, to ease need of cloning etc. 2023-01-07 17:04:58 -05:00
Greg Johnston
a6b6864bc5 Merge branch 'adjust-tracing' of https://github.com/gbj/leptos into adjust-tracing 2023-01-07 16:27:33 -05:00
Greg Johnston
063b946cd4 Remove unnecessary log 2023-01-07 16:27:25 -05:00
Greg Johnston
5a2c9ea345 Merge branch 'main' into adjust-tracing 2023-01-07 16:26:20 -05:00
Greg Johnston
808d87598b Tracing for events and elements. 2023-01-07 16:20:00 -05:00
Greg Johnston
0956c48b1e Merge pull request #266 from gbj/fix-meta-panic
Adjust default features for `meta` and `router`
2023-01-07 14:44:23 -05:00
Greg Johnston
8915e2615b Adjust default features for meta and router 2023-01-07 14:43:32 -05:00
Greg Johnston
7f47134058 Merge pull request #265 from martinfrances107/needless_borrowed_reference
Clippy: Minor needless_borrowed_reference.
2023-01-07 14:21:58 -05:00
Greg Johnston
af7b93fa1e Merge pull request #128 from akesson/workspace-features
Workspace features
2023-01-07 14:19:56 -05:00
Greg Johnston
ed940f577a Add tracing for event handlers 2023-01-07 13:32:40 -05:00
Martin
916f30a07b Clippy: Minor needless_borrowed_reference. 2023-01-07 18:28:42 +00:00
Greg Johnston
e01c565de1 Improve tracing formatting 2023-01-07 13:16:30 -05:00
Greg Johnston
dffe195cdc Fix two warnings 2023-01-07 13:16:20 -05:00
Greg Johnston
a5e2587555 Merge pull request #261 from martinfrances107/Clippy_removed_clone_where_possible
Clippy: Removed stray calls to .clone().
2023-01-07 12:47:06 -05:00
Greg Johnston
af8889fab2 Merge pull request #262 from martinfrances107/uninlined_format_args
Minor: Clippy format!() all variables now inlined.
2023-01-07 12:42:56 -05:00
Greg Johnston
267c1cfc34 Merge pull request #263 from martinfrances107/if_let_some
Removed clippy::single_match issue.
2023-01-07 12:40:55 -05:00
Greg Johnston
3498378e60 Merge pull request #260 from jquesada2016/into_signal_traits
added `IntoSignal` and `IntoSignalSetter` helper traits
2023-01-07 12:40:15 -05:00
hakesson
f8c680d14d Integrations with workspace dependencies 2023-01-07 18:05:35 +01:00
hakesson
b852e459a9 Unify workspace dependencies 2023-01-07 18:00:37 +01:00
hakesson
681f10ec8d Workspace-based versioning 2023-01-07 17:35:02 +01:00
Martin
1d480791a1 Removed clippy::single_match issue. 2023-01-07 16:08:17 +00:00
Martin
7acc309f66 Minor: Clippy format!() all variables now inlined. 2023-01-07 15:46:47 +00:00
Martin
9527de15ed Removed stray calls to .clone(). 2023-01-07 14:53:59 +00:00
Jose Quesada
aeb25a715a added IntoSignal and IntoSignalSetter helper traits 2023-01-07 08:20:27 -06:00
Greg Johnston
46e91a538c Merge branch 'main' of https://github.com/gbj/leptos 2023-01-07 08:32:45 -05:00
Greg Johnston
1fe526c99c Remove erroneous log 2023-01-07 08:32:39 -05:00
Greg Johnston
6b05918807 Merge pull request #257 from gbj/ci-disk-space
Improve CI disk space usage
2023-01-07 07:44:10 -05:00
Greg Johnston
05d2eb8ce0 Improve CI disk space usage 2023-01-07 07:43:52 -05:00
Greg Johnston
e12c2d9769 Merge pull request #252 from gbj/additional-meta-tags
Additional meta tags — closes issue #158
2023-01-07 07:37:02 -05:00
Greg Johnston
825245b65f Merge pull request #256 from gbj/router-tests
Fix router tests when no features enabled
2023-01-07 07:36:51 -05:00
Greg Johnston
ef067f18e1 Fix router tests when no features enabled 2023-01-07 07:36:27 -05:00
Greg Johnston
844dc21efd Merge pull request #255 from martinfrances107/#253_cargo_doc_warnings_rename_EachKey_to_Each
#254 Minor: In docs, Rename EachKey to Each.
2023-01-07 07:25:34 -05:00
Greg Johnston
1a00e99a24 Merge pull request #254 from martinfrances107/#253_unbalanced_tags
#254 Minor: Unbalanced tags.
2023-01-07 07:25:03 -05:00
Martin
6c5bcf30ba #254 Minor: In docs, Rename EachKey to Each. 2023-01-07 11:51:52 +00:00
Martin
be8ffe935d #254 Minor: Unbalanced tags. 2023-01-07 11:22:36 +00:00
Greg Johnston
0b80bba4ec Fix tests 2023-01-06 23:04:25 -05:00
Greg Johnston
9cc38988d8 Corrects style docs 2023-01-06 22:56:23 -05:00
Greg Johnston
0d92a5dec8 Add <Script/> and <Style/> components 2023-01-06 22:54:35 -05:00
benwis
677e4f2540 Leptos can now generate routes and provide them to the Axum router. More
testing and Actix version to come
2023-01-06 19:52:38 -08:00
Greg Johnston
0029e1d8f7 Merge pull request #251 from martinfrances107/bump_actions_checkout
Bump actions/checkout to version@3
2023-01-06 17:47:21 -05:00
Greg Johnston
635aa5c681 Merge pull request #250 from jquesada2016/on_mount
added `HtmlElement::on_mount`
2023-01-06 17:46:29 -05:00
Martin
f5c4c9448c Bump actions/checkout to version@3 2023-01-06 22:31:13 +00:00
benwis
63b1837315 First pass of method to generate routelist 2023-01-06 14:08:45 -08:00
Greg Johnston
bc43a9d329 Use builder syntax and refactor tag registration 2023-01-06 16:49:26 -05:00
Greg Johnston
1850c28d3a Add <Link/> and refactor <Stylesheet/> to use it 2023-01-06 16:06:03 -05:00
Greg Johnston
319a058e63 Fix relative route for stylesheet in hackernews 2023-01-06 16:06:03 -05:00
Greg Johnston
678e49268f Merge pull request #248 from gbj/tracing
Adding `tracing` to `leptos_reactive`
2023-01-06 15:18:54 -05:00
Jose Quesada
6df4a6f120 fixed broken compilation within on_mount 2023-01-06 14:17:35 -06:00
Jose Quesada
73c6bbb225 updated to use the equest animation frame method in helpers.rs 2023-01-06 14:02:49 -06:00
Jose Quesada
fa57085946 added HtmlElement::on_mount 2023-01-06 12:24:24 -06:00
Greg Johnston
aef589cd24 Merge pull request #249 from gbj/router-tests
Add all the missing `router` tests
2023-01-06 12:49:44 -05:00
Greg Johnston
05ffd8c989 Add all the missing router tests 2023-01-06 12:48:45 -05:00
Greg Johnston
1125a5f7cb Additional tracing 2023-01-06 12:30:19 -05:00
Greg Johnston
dfba1d9656 Memos 2023-01-06 11:38:03 -05:00
Greg Johnston
96418ed684 Start work on instrumenting leptos_reactive 2023-01-06 11:38:03 -05:00
Greg Johnston
b010233bb4 Merge pull request #242 from jquesada2016/signal_default
impl `Default` for `SignalSetter<T>`
2023-01-06 10:31:29 -05:00
Greg Johnston
7e28f56f01 Merge pull request #247 from gbj/fix-integration-event-name
Correct `leptos_autoreload` event variable name
2023-01-06 09:50:45 -05:00
Greg Johnston
dd35c31db1 Correct leptos_autoreload event variable name 2023-01-06 09:50:29 -05:00
Jose Quesada
c9ac4ed2b5 added Signal::default method 2023-01-06 08:34:15 -06:00
Jose Quesada
7631ce3b09 Revert "added DefaultSignal"
This reverts commit a5988c59ee.
2023-01-06 08:26:10 -06:00
Jose Quesada
a5988c59ee added DefaultSignal 2023-01-05 17:06:06 -06:00
Jose Quesada
9ba807f79b impl Default for SignalSetter<T> 2023-01-05 15:47:31 -06:00
Greg Johnston
9d8627b337 Merge branch 'main' of https://github.com/gbj/leptos 2023-01-05 11:08:11 -05:00
Greg Johnston
64bf01c59e Reduce CI load with skipped feature sets 2023-01-05 11:08:07 -05:00
Greg Johnston
ed023c8970 Merge pull request #239 from gbj/router-off-by-one
Fixes off-by-one error in the router that was causing inappropriate scope disposal
2023-01-05 09:47:39 -05:00
Greg Johnston
13bdef22bd Fixes off-by-one error in the router that was causing inappropriate scope disposal 2023-01-05 09:47:03 -05:00
Greg Johnston
6f49a6c12a Merge pull request #237 from gbj/additional-meta-tags
Better `leptos_meta` component unloading
2023-01-05 08:20:13 -05:00
Greg Johnston
7db292779b Correct on_cleanup import 2023-01-04 22:41:46 -05:00
Greg Johnston
e2496e01d0 Correctly hydrate stylesheets, and correctly clean up stylesheets and metadata 2023-01-04 22:39:54 -05:00
Greg Johnston
d5bda04306 <Outlet/> should dispose of child scopes if it needs to 2023-01-04 22:39:32 -05:00
Greg Johnston
9165242744 Merge pull request #236 from gbj/fix-outlet-hydration-mismatch
Fix `<Outlet/>` hydration mismatch
2023-01-04 22:09:00 -05:00
Greg Johnston
927fe0949f Merge pull request #235 from gbj/effect-cleanup
Signals were not properly registering themselves as sources for their…
2023-01-04 16:57:29 -05:00
Greg Johnston
459216a30e Fix <Outlet/> hydration mismatch 2023-01-04 16:56:47 -05:00
Greg Johnston
c7fa041469 Working on disposing metadata tags 2023-01-04 16:56:04 -05:00
Greg Johnston
cab7360bef Fix hydration mismatch in <Outlet/> 2023-01-04 15:32:39 -05:00
Greg Johnston
159ec4a7bd Signals were not properly registering themselves as sources for their effects, which meant effects were possibly over-running. 2023-01-04 11:29:08 -05:00
Greg Johnston
ae40f3134a Merge pull request #233 from kdwarn/main
Fix links/names to a couple examples
2023-01-04 11:11:04 -05:00
Greg Johnston
3c080e0564 Merge pull request #232 from gbj/custom-events-in-macro
`leptos_macro` improvements to `class:`, `prop:`, `on:`, `:undelegate…
2023-01-04 11:10:19 -05:00
Greg Johnston
e8c1bf5055 #[prop] docs 2023-01-04 11:10:03 -05:00
Greg Johnston
2a4a5f75c9 Remove unused doc_comment crate 2023-01-04 10:42:25 -05:00
Greg Johnston
91b65654d6 Fix typed event docs 2023-01-04 10:40:35 -05:00
Kris Warner
dcca6e4e17 Fix name/link for parent_child 2023-01-04 10:25:41 -05:00
Kris Warner
4550545e4f Fix link/name of counters_stable 2023-01-04 10:18:38 -05:00
Greg Johnston
af1a4492e8 leptos_macro improvements to class:, prop:, on:, :undelegated, and events 2023-01-04 00:25:53 -05:00
Greg Johnston
6b1b4463a0 Fix server docs 2023-01-03 23:22:06 -05:00
Greg Johnston
632267c13a Merge pull request #231 from gbj/router-changes
Close issue #229 and update router docs
2023-01-03 21:51:22 -05:00
Greg Johnston
a349707e1f Merge pull request #230 from gbj/server-docs-and-debug
Improve docs and debugging tools for server functions (closes #225)
2023-01-03 21:51:10 -05:00
Greg Johnston
84fa6cd3a8 Merge pull request #228 from benwis/responseoptions_helpers
Add a redirect() function and some helpful utility functions for ResponseParts and ResponseOptions
2023-01-03 21:51:00 -05:00
Ben Wishovich
05468d3307 You WILL change your doc comments 2023-01-03 17:33:22 -08:00
Greg Johnston
0da88f39cd Improve docs and debugging tools for server functions (closes #225) 2023-01-03 20:05:47 -05:00
Greg Johnston
5dffb0a803 Document how to modularize/externalize route definitions 2023-01-03 19:38:11 -05:00
Greg Johnston
e2a5c2d78f Fix issues with route matching on different sub-routes with same path (closes issue #229) 2023-01-03 19:32:58 -05:00
Greg Johnston
ca679ec496 chore: clear warning 2023-01-03 19:06:59 -05:00
Greg Johnston
10282857fe chore: clear warnings 2023-01-03 18:47:21 -05:00
Greg Johnston
263d5b1d89 Allow path prop on <Route/> to be any type that impl std::fmt::Display 2023-01-03 18:37:43 -05:00
Greg Johnston
6a4cbbf266 Specify html::a to suppress warning 2023-01-03 16:07:51 -05:00
Greg Johnston
8d14972808 Merge branch 'main' of https://github.com/gbj/leptos 2023-01-03 15:52:33 -05:00
Greg Johnston
441eb1697e Reduce CI load by omitting tracing feature from CI testing 2023-01-03 15:52:29 -05:00
Ben Wishovich
64e6eedb4d Add a redirect() function and some helpful utility functions for ResponseParts and ResponseOptions 2023-01-03 10:35:30 -08:00
Greg Johnston
78d965cc91 Merge pull request #220 from jquesada2016/view_on_undelegated
added on:eventname:undelegated support
2023-01-03 13:07:22 -05:00
Jose Quesada
28dce925b0 relaxed parse_event to be undelegated only when :undelegated appears at the end of the event 2023-01-03 08:54:52 -06:00
Greg Johnston
a2943c4649 Fix counters_isomorphic 2023-01-02 18:37:10 -05:00
Greg Johnston
d4b5b958f3 0.1.0-beta 2023-01-02 16:52:18 -05:00
Greg Johnston
9537cafe25 Add version for publishing 2023-01-02 16:49:45 -05:00
Greg Johnston
95dd252c14 Disable for publish 2023-01-02 16:41:08 -05:00
Greg Johnston
755ceb7d75 0.1.0-beta 2023-01-02 16:35:00 -05:00
Greg Johnston
d5b74dacc8 Merge pull request #223 from gbj/build-examples-ci
Add CI back to build examples
2023-01-02 16:34:29 -05:00
Greg Johnston
411fc51ea2 Clean up examples 2023-01-02 16:20:05 -05:00
Greg Johnston
e714cac0ec Add missing makefiles 2023-01-02 16:19:52 -05:00
Greg Johnston
ab0b687943 Merge pull request #222 from gbj/build-examples-ci
Add `build-examples` task to `cargo make` CI
2023-01-02 13:35:45 -05:00
Greg Johnston
7f21ee97a8 Fix counter_isomorphic import 2023-01-02 13:34:56 -05:00
Greg Johnston
0ed56d382d Add build-examples task to cargo make CI 2023-01-02 13:29:37 -05:00
Greg Johnston
a47cac6e3c Merge pull request #221 from gbj/fixing-stable
Finalizing `stable` support
2023-01-02 13:24:27 -05:00
Greg Johnston
edbd3612b3 stable for leptos_macro 2023-01-02 13:04:56 -05:00
Greg Johnston
e2517c99b8 Backtrace not supported on stable 2023-01-02 12:55:26 -05:00
Greg Johnston
2b01bf99b4 enum Default not supported on stable 2023-01-02 12:55:16 -05:00
Greg Johnston
bd5bd71a21 chore: clear warning 2023-01-02 12:55:04 -05:00
Greg Johnston
60187961a0 Merge pull request #219 from jquesada2016/leptos_dom_stable
Stable support for `leptos_dom`
2023-01-02 12:09:48 -05:00
Jose Quesada
1344f113c5 added on:eventname:undelegated support 2023-01-02 10:36:08 -06:00
Greg Johnston
96bbb86346 Merge pull request #218 from gbj/stylesheet-hydration
Correct hydration behavior of `<Stylesheet id=.../>` (necessary for `…
2023-01-02 10:23:35 -05:00
Jose Quesada
7478315970 forgot to commit new dependencies 2023-01-02 09:01:57 -06:00
Jose Quesada
b894444b8d removed drain_filter feature flag 2023-01-02 08:28:05 -06:00
Jose Quesada
9f8bcd6fb1 removed iter_intersperse feature flag` 2023-01-02 08:20:45 -06:00
Jose Quesada
d82781abbd removed thread_local feature flag 2023-01-02 08:18:19 -06:00
Jose Quesada
f8c4cac6d3 removed once_cell feature flag 2023-01-02 07:52:30 -06:00
Greg Johnston
4264b15aab Correct hydration behavior of <Stylesheet id=.../> (necessary for cargo-leptos CSS reloading) 2023-01-01 22:56:17 -05:00
Greg Johnston
168f9d3a45 Merge pull request #217 from gbj/action-docs-ci
Fix `Action` and `create_action` docs to match new API
2023-01-01 21:36:15 -05:00
Greg Johnston
9663555195 Fix Action and create_action docs to match new API 2023-01-01 19:44:50 -05:00
Greg Johnston
e92176029c Merge pull request #216 from gbj/context-warning
Revert confusingly-aggressive shadowed-context warning
2023-01-01 17:40:54 -05:00
Greg Johnston
fe820c48c8 Revert confusingly-aggressive shadowed-context warning 2023-01-01 17:40:39 -05:00
Greg Johnston
87cd4b8f00 Merge pull request #214 from gbj/fix-tailwind-example
Small fixes to Tailwind example
2023-01-01 08:09:36 -05:00
Greg Johnston
3a5e3aea99 Small fixes to Tailwind example 2023-01-01 08:09:24 -05:00
Greg Johnston
9ba06cd604 Merge pull request #213 from gbj/fix-hydration-mismatch
Closes #212
2023-01-01 08:04:10 -05:00
Greg Johnston
e8eb55ca5c Make sure tag names are uppercased in debug assertions where they're uppercased 2023-01-01 08:03:26 -05:00
Greg Johnston
7946df8bfc Merge pull request #209 from benwis/cargo-leptos-release-testing
Update all examples to use cargo-leptos and patch integrations for latest cargo-leptos support
2023-01-01 07:56:41 -05:00
Ben Wishovich
827b787c91 Bugfixes, using cargo-leptos for CSS, and updating READMEs. 2022-12-31 18:39:05 -08:00
Greg Johnston
795270447b Merge pull request #208 from jquesada2016/207
fixes compiler recursion limit on `View::on`
2022-12-31 19:15:28 -05:00
Ben Wishovich
01c00eee6b Update SSR Readmes with new instructions 2022-12-31 16:06:54 -08:00
Ben Wishovich
f45d33db73 Move the examples out of the workspace, and standardize naming. All of the SSR examples now work with cargo-leptos 2022-12-31 15:52:19 -08:00
Jose Quesada
60e2f34456 changed View::on to not require manually boxing the closure 2022-12-31 09:59:48 -06:00
Jose Quesada
7ec82c8df3 boxing View::on closure to fix compiler recursion error 2022-12-31 09:54:13 -06:00
Greg Johnston
d5f8d3a9b7 Merge pull request #206 from jquesada2016/199
fixed components only rendering `<() />` on release
2022-12-31 09:22:09 -05:00
Jose Quesada
2a1b531bd2 fixed components only rendering <() /> on release 2022-12-31 08:08:14 -06:00
Greg Johnston
f5c476cfd5 Merge pull request #205 from gbj/meta-context-warning
Fix warning about MetaContext so it's less misleading.
2022-12-30 20:04:46 -05:00
Greg Johnston
26b28be436 Fix warning about MetaContext so it's less misleading. 2022-12-30 19:30:35 -05:00
Ben Wishovich
60f0bf23fd Merge branch 'main' into cargo-leptos-release-testing 2022-12-30 16:17:50 -08:00
Ben Wishovich
442dc1e041 More changes to the examples 2022-12-30 16:17:17 -08:00
Greg Johnston
c438b46eb1 Merge pull request #200 from gbj/duplicating-text-fix
Fixing duplicating-text-node issue in `DynChild`
2022-12-30 19:11:43 -05:00
Greg Johnston
2a399f05ac Merge pull request #202 from Gentle/detect_tag_type
ambiguous tags inherit the type of their parent (svg/mathml/html)
2022-12-30 19:11:25 -05:00
Greg Johnston
6e1bc42879 Merge pull request #204 from gbj/debug-shadowed-context
Give warning when shadowing a context in debug mode
2022-12-30 19:11:02 -05:00
Greg Johnston
7ad94cc520 Merge pull request #203 from gbj/stored-value
`store_value`
2022-12-30 19:10:25 -05:00
Ramon Klass
c3a7ef0357 ambiguous tags inherit the type of their parent 2022-12-30 23:38:51 +01:00
Greg Johnston
8ee521787e Give warning when shadowing a context in debug mode 2022-12-30 17:11:34 -05:00
Greg Johnston
04c85d6eb0 Fix Axum example 2022-12-30 16:55:50 -05:00
Greg Johnston
71d278927b Update examples to new action APIs 2022-12-30 15:44:25 -05:00
Greg Johnston
cc1d15989e Update router to new action APIs 2022-12-30 15:36:01 -05:00
Greg Johnston
2c614722f4 Make Action and MultiAction Copy by backing them with a StoredValue 2022-12-30 15:29:35 -05:00
Greg Johnston
98d151f5fb Make Signal and SignalSetter Copy by backing them with StoredValue when needed 2022-12-30 15:10:37 -05:00
Greg Johnston
5a9a681d8a Create store_value and StoredValue, allowing you to stash things inside the reactive system in exchange for a Copy + 'static wrapper. 2022-12-30 15:10:28 -05:00
Ben Wishovich
8eaa0b0c15 Merge branch 'main' into cargo-leptos-release-testing 2022-12-30 11:04:43 -08:00
Ben Wishovich
c3fbf13ef3 No leading slashes, and a working todo-app-sqlite example. Improved config section detection 2022-12-30 11:01:01 -08:00
Greg Johnston
54f666c957 Merge pull request #201 from gbj/custom-events-dont-bubble
Fixes issue #178
2022-12-30 12:20:48 -05:00
Greg Johnston
b318449ee7 Issue #178 2022-12-30 11:41:21 -05:00
Greg Johnston
59c291a1e5 Could it be this simple? 2022-12-30 10:47:01 -05:00
Greg Johnston
6c7b20ce77 Merge pull request #197 from luckynumberke7in/patch-2
Fix a few typos in README.md
2022-12-30 08:19:10 -05:00
Ke7in
9a00f7f492 Fix a few typos in README.md
Minor, but I noticed 1 while reading the file and decided to skim the rest of the file.
2022-12-29 23:23:43 -05:00
Greg Johnston
26e90d1959 Merge pull request #196 from gbj/cleanup
Clean up issues relating to `0.1.0` merge
2022-12-29 20:44:31 -05:00
Ben Wishovich
1f1d675d17 Basic cargo-leptos test 2022-12-29 16:42:05 -08:00
Greg Johnston
9bde885b9d Fix suspense in story page 2022-12-29 19:28:10 -05:00
Greg Johnston
383f8a409d Add <Suspense/> to story and user pages 2022-12-29 19:17:35 -05:00
Greg Johnston
b98bacdcab Remove logs 2022-12-29 18:51:39 -05:00
Greg Johnston
d3d71875da FIXME DynChild issue 2022-12-29 18:48:21 -05:00
Greg Johnston
e06946e5a4 stable support for router 2022-12-29 18:40:50 -05:00
Greg Johnston
c485a391ee Update README.md 2022-12-29 18:25:45 -05:00
Greg Johnston
cc48ff72ad Prep for stable support 2022-12-29 18:21:24 -05:00
Greg Johnston
b2cf953c07 Example fix 2022-12-29 18:21:18 -05:00
Greg Johnston
f8af065c0e Adjustments to README 2022-12-29 18:21:08 -05:00
Greg Johnston
333f60cfb7 Changes for stable in router and meta 2022-12-29 18:10:14 -05:00
Greg Johnston
cd9fe66fbb Debug bound 2022-12-29 18:01:47 -05:00
Greg Johnston
3bb9e93c69 Debug bounds 2022-12-29 18:01:01 -05:00
Greg Johnston
f9474def96 Relaxed Debug bounds 2022-12-29 17:43:17 -05:00
Greg Johnston
d7dba85f2d Missing changes re: docs 2022-12-29 17:43:06 -05:00
Greg Johnston
94af8f26ca Fix site-root 2022-12-29 17:39:08 -05:00
Greg Johnston
19dabb6b6a Clear up warnings in the example 2022-12-29 17:39:04 -05:00
Greg Johnston
15b5f7545a Use <Transition/> here for that silky-smooth optimistic UI update 2022-12-29 17:35:46 -05:00
Greg Johnston
9399fc7b4f Removed old/broken fix for hydration under <Suspense/> 2022-12-29 17:30:33 -05:00
Greg Johnston
5d8d5d9910 SocketAddr? I hardly know her! (missing import from merge) 2022-12-29 16:01:37 -05:00
Greg Johnston
e6a1255140 Merge pull request #119 from jquesada2016/leptos_dom_v2
leptos_dom v2
2022-12-29 12:21:13 -05:00
Greg Johnston
528a9d7a6f Fix merge 2022-12-29 12:13:52 -05:00
Greg Johnston
f28da0770f Fix leptos_config version 2022-12-29 12:13:45 -05:00
Jose Quesada
0145b01da5 impl IntoView for &View 2022-12-29 09:55:35 -06:00
Greg Johnston
725ea8a01e Merge branch 'jquesada2016-leptos_dom_v2' 2022-12-29 09:32:35 -05:00
Greg Johnston
70f6297277 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into jquesada2016-leptos_dom_v2 2022-12-29 09:32:12 -05:00
Greg Johnston
e595d35c8b Fix CSS location for hackernews-axum 2022-12-29 08:50:43 -05:00
Greg Johnston
c44693e0a4 Use #[component] macro for leptos_meta to generate docs 2022-12-29 08:46:41 -05:00
Greg Johnston
b86e7f33dc Bump versions for new cargo-leptos compatible integrations 2022-12-29 08:04:22 -05:00
Greg Johnston
a603531409 Typos 2022-12-29 08:02:56 -05:00
Greg Johnston
f47fad3ed5 Merge pull request #177 from benwis/cargo-leptos-beta
Changes to leptos, leptos_meta, leptos_actix/leptos_axum, and leptos_config to support cargo-leptos-beta
2022-12-29 07:48:38 -05:00
Greg Johnston
1cb03914ab Merge pull request #185 from snapbug/stable-build-fix
Fix build errors in `counter-isomorphic` when using `stable`
2022-12-29 07:44:56 -05:00
Jose Quesada
67c5eda099 removed clone bount on the type argument of SignalSetter 2022-12-28 21:14:10 -06:00
Jose Quesada
63e70db736 removed EventHandler trait 2022-12-28 17:49:10 -06:00
Jose Quesada
8acbc579e0 fixed broken undelegated type 2022-12-28 15:38:13 -06:00
Jose Quesada
28bb3f81aa made ev::undelegated lowercase to match the rest of the event names 2022-12-28 15:28:59 -06:00
Greg Johnston
e8424138ce Fix TOML 2022-12-28 15:06:52 -05:00
Greg Johnston
4b1fce4c9c Revert "Merge branch 'main' into pr/119"
This reverts commit 63f680f37d, reversing
changes made to 50ba796f49.
2022-12-28 15:06:46 -05:00
Greg Johnston
fd2a2bd5f4 Fixing merge issues 2022-12-28 14:51:01 -05:00
Greg Johnston
f09ded454d Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into pr/119 2022-12-28 14:48:03 -05:00
Greg Johnston
a2f85feb57 Update Readme 2022-12-28 14:41:19 -05:00
Greg Johnston
d64ca366fc Fix merge 2022-12-28 14:22:03 -05:00
Greg Johnston
63f680f37d Merge branch 'main' into pr/119 2022-12-28 14:21:54 -05:00
Greg Johnston
50ba796f49 Fix leptos_server tests 2022-12-28 13:26:10 -05:00
Jose Quesada
f3b62bcf88 impl HtmlElement::inner_html for SSR 2022-12-28 11:34:27 -06:00
Jose Quesada
57c72c038c impl HtmlElement::inner_html for web targets, SSR still TODO 2022-12-28 11:17:47 -06:00
Jose Quesada
4340fbfc78 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-28 10:52:06 -06:00
Jose Quesada
4e1753fc71 moved #[component] tracing support behind a tracing feature flag 2022-12-28 10:51:55 -06:00
Greg Johnston
f30310a64a Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-28 11:33:29 -05:00
Greg Johnston
e3c4e9f6a4 chores: fix failing tests, update docs, suppress warnings 2022-12-28 11:33:26 -05:00
Jose Quesada
494deef9b6 maybe possibly perhaps fixed broken tracing dep 2022-12-28 09:53:11 -06:00
Jose Quesada
0da8d0113c added clone: to components in view! macro to help with move dilemmaa 2022-12-28 09:24:52 -06:00
Greg Johnston
dac69b9802 Port hackernews-axum 2022-12-28 08:53:05 -05:00
Jose Quesada
3c1e1e12d2 component move fix would break scope continuity 2022-12-28 07:44:41 -06:00
Jose Quesada
0e179d0cb5 component move fix would break scope continuity
This reverts commit 4dd5768a66.
2022-12-28 07:36:05 -06:00
Greg Johnston
55b27f7aec Fix <Meta/> tag hydration lookup 2022-12-28 08:19:56 -05:00
Jose Quesada
4467d060b6 fixed duplicate imports on web 2022-12-27 20:18:46 -06:00
Jose Quesada
4dd5768a66 fixed move dilema on component children 2022-12-27 20:14:10 -06:00
Jose Quesada
a3f090c4df added LazyView to fix view! macro move dilema 2022-12-27 20:12:59 -06:00
Ben Wishovich
5729655657 Merge remote-tracking branch 'origin/cargo-leptos-beta' into cargo-leptos-beta 2022-12-27 13:02:13 -08:00
Ben Wishovich
f2ed521de8 Missing .is_ok() and more examples changes 2022-12-27 13:01:40 -08:00
Ben Wishovich
f8f0d9fae0 Merge branch 'main' into cargo-leptos-beta 2022-12-27 12:49:17 -08:00
Ben Wishovich
e23c05a1df Remove unused derives 2022-12-27 11:01:20 -08:00
Ben Wishovich
be94c1b846 Update examples to camelcase and add missing fields for feature flags. Should be working with cargo-leptos beta again 2022-12-27 10:58:05 -08:00
Jose Quesada
b3c4c77dee now unwrapping type when documenting a field which has #[prop(strip_option)] 2022-12-27 12:20:14 -06:00
Jose Quesada
8b81425b21 explicit handler type to help compiler type inference 2022-12-27 08:46:09 -06:00
Jose Quesada
04e3e7a9a6 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-27 08:33:22 -06:00
Jose Quesada
ab2d554dc3 now only adding event handlers Some(_) and FnMut; called cargo fmt which is why more files were edited 2022-12-27 08:33:09 -06:00
Greg Johnston
c712cc8937 chore: clippy 2022-12-26 17:49:32 -05:00
Greg Johnston
6077966cd7 Streaming SSR for <Suspense/> in release mode 2022-12-26 17:47:26 -05:00
Greg Johnston
3179b2a9e5 Remove duplicate 2022-12-26 17:25:18 -05:00
Greg Johnston
a68d276c90 Merge pull request #188 from tshepang/patch-1
readme: fix indentation of code block
2022-12-26 17:16:03 -05:00
Greg Johnston
bf3bba3794 Merge pull request #176 from ultrasaurus/nightly-readme
info about how to set up nightly -> README
2022-12-26 17:15:30 -05:00
Sarah Allen
17eb571ef3 remove --allow-downgrade option since not required 2022-12-26 11:00:27 -08:00
Greg Johnston
ebd7080149 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-26 11:38:27 -05:00
Greg Johnston
f1a148caf8 Remove errant Clone bound on Signal<T> by implementing explicitly 2022-12-26 11:38:25 -05:00
Jose Quesada
a5351dd33d fixed broken cfg 2022-12-26 09:51:36 -06:00
Jose Quesada
a15b3dd882 now using a shared marker to check if a Each has already been mounted, rather than calling out to JS 2022-12-26 09:42:37 -06:00
Jose Quesada
d42b79b261 now using a shared marker to check if a component has already been mounted, rather than calling out to JS 2022-12-26 09:37:32 -06:00
Jose Quesada
6cd136ec9b Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-26 08:59:11 -06:00
Jose Quesada
85b72f5b68 added support for moving views around in the DOM 2022-12-26 08:58:58 -06:00
Greg Johnston
2bd0c38304 Properly detect and namespace SVG/MathML 2022-12-26 08:21:36 -05:00
Greg Johnston
9dc30da3e9 Fix component children example in docs 2022-12-26 08:03:40 -05:00
Tshepang Mbambo
3436cf7fbf readme: fix indentation of code block 2022-12-26 06:29:12 +02:00
Greg Johnston
38ef93d862 Fix deps 2022-12-25 23:14:10 -05:00
Greg Johnston
0e437cac68 Update README 2022-12-25 23:13:27 -05:00
Greg Johnston
98e3f5a155 Remove dev-deps for publish 2022-12-25 23:11:08 -05:00
Greg Johnston
a55ce8f752 Fix deps 2022-12-25 23:08:00 -05:00
Greg Johnston
469a65ad7a Remove dev-deps for publish 2022-12-25 23:07:42 -05:00
Greg Johnston
8a8c00455e Remove version of dev-deps 2022-12-25 23:06:20 -05:00
Greg Johnston
2048e89109 Remove dev-dependency (for cargo publish reasons) 2022-12-25 23:03:43 -05:00
Greg Johnston
5540bb8e8c Bump version to 0.1.0-alpha 2022-12-25 22:58:07 -05:00
Greg Johnston
86df770dad chores: getting tests fixed, etc. 2022-12-25 22:53:52 -05:00
Greg Johnston
535bd69b2a Merge pull request #186 from luckynumberke7in/patch-1
Update COMMON_BUGS.md to fix typo
2022-12-25 20:48:40 -05:00
Ke7in
1b0200390b Update COMMON_BUGS.md to fix typo
```rust
let (b, set_a) = create_signal(cx, false); // should be set_b
```
2022-12-25 18:27:52 -05:00
Greg Johnston
e05778726b Update docs 2022-12-25 16:06:29 -05:00
Matt Crane
587a85baaf Fix erros in counter-isomorphic with stable 2022-12-24 12:13:35 -08:00
Ben Wishovich
ff0d058a3e leptos_watch is not a bool 2022-12-24 10:30:29 -08:00
Jose Quesada
623bb7cb3f Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-24 08:45:43 -06:00
Jose Quesada
fc062e6829 fixed the type of math elements 2022-12-24 08:45:36 -06:00
Greg Johnston
479c11e3f8 MUCH better solution to hydration mismatch when resources read not under Suspense 2022-12-24 08:24:56 -05:00
Greg Johnston
bf9587c349 Attempt at Transition 2022-12-24 07:39:43 -05:00
Greg Johnston
b3da8a5dba Fix SVG warning fix 2022-12-24 07:39:25 -05:00
Greg Johnston
d3f2cae07a Fix SVG warnings 2022-12-24 07:28:34 -05:00
Greg Johnston
8c4dcbeddc Fix paths for imports 2022-12-23 17:05:52 -05:00
Greg Johnston
a4747596fa Only stream Resources if they're under a Suspense to fix rendering issue 2022-12-23 17:01:22 -05:00
Greg Johnston
af68da0a9a Remove web by default 2022-12-23 17:01:06 -05:00
Greg Johnston
48e1d6cfab Recursive components allowed 2022-12-23 17:00:52 -05:00
Greg Johnston
a4740d6c06 Remove web by default 2022-12-23 17:00:42 -05:00
Jose Quesada
ae506fced6 fixed name mismatch 2022-12-23 14:51:27 -06:00
Jose Quesada
86394105dd fixed name collision within components so that recursion is possible 2022-12-23 14:47:57 -06:00
Jose Quesada
7028dd8b3d fixed math namespace 2022-12-23 14:34:35 -06:00
Jose Quesada
8092bf1962 untoggled wasm32 target 2022-12-23 14:22:16 -06:00
Jose Quesada
2d97790ab9 fixed imports on non-web 2022-12-23 14:17:54 -06:00
Jose Quesada
ef846e7b88 added all math elements 2022-12-23 14:09:46 -06:00
Jose Quesada
d78ee8c3c9 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-23 14:07:01 -06:00
Jose Quesada
d1ece97575 added all svg elements 2022-12-23 14:06:55 -06:00
Greg Johnston
c24958bec4 Fix paths in hackernews example 2022-12-23 14:35:02 -05:00
Greg Johnston
8e1c165427 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-23 14:32:26 -05:00
Greg Johnston
50c9c38b7d Fix JS path 2022-12-23 14:24:59 -05:00
Greg Johnston
232776f9a6 Add example to Cargo.toml 2022-12-23 14:23:52 -05:00
Greg Johnston
629ac01484 merge todo-app-sqlite-axum 2022-12-23 14:23:38 -05:00
Greg Johnston
f20c74fa98 SSR changes to support integrations 2022-12-23 14:23:06 -05:00
Greg Johnston
2499755a9e Merge main integrations in 2022-12-23 14:22:49 -05:00
Greg Johnston
f17f651986 Clean up example 2022-12-23 13:30:22 -05:00
Greg Johnston
c1d6ff51a6 Update meta and router versions 2022-12-23 13:19:51 -05:00
Greg Johnston
4839bfbb29 Tailwind example ported 2022-12-23 13:10:45 -05:00
Greg Johnston
391fe89542 0.0.21 2022-12-23 13:01:15 -05:00
Greg Johnston
f54ffab888 Update integration versions 2022-12-23 12:43:18 -05:00
Jose Quesada
7ee0c01594 fixed non-web builds 2022-12-23 11:19:39 -06:00
Jose Quesada
6ce90fa49d revert default build target 2022-12-23 11:16:28 -06:00
Jose Quesada
c96965ab64 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-23 11:10:01 -06:00
Jose Quesada
5def2a72bc impl View::on and renamed IntoElement to ElementDescriptor 2022-12-23 11:09:55 -06:00
Greg Johnston
a648f084c6 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-23 11:40:59 -05:00
Greg Johnston
590ec40e0c Final Suspense fix? 2022-12-23 11:40:57 -05:00
Greg Johnston
6354b79588 Use Transition in example 2022-12-23 11:34:20 -05:00
Greg Johnston
d95dc1858c Fix merged leptos_reactive so that resources are streamed properly 2022-12-23 11:33:17 -05:00
Greg Johnston
558b13dc0e Fix merged leptos_reactive so that resources are streamed properly 2022-12-23 11:33:05 -05:00
Greg Johnston
43bbd2f33e Merge branch 'main' of https://github.com/gbj/leptos 2022-12-23 10:25:51 -05:00
Greg Johnston
833eee6639 Create shared_context by default in SSR 2022-12-23 10:25:48 -05:00
Greg Johnston
feb7961bd0 Created shared_context by default in SSR 2022-12-23 10:24:44 -05:00
Greg Johnston
8aa05f8f3d Merge pull request #181 from gbj/relax-debug-trait-bounds
Relax the `Debug` trait bounds on various types in `leptos_reactive`
2022-12-23 10:05:49 -05:00
Jose Quesada
fa87bc6f19 added transparent to `<For /> 2022-12-23 08:39:06 -06:00
Greg Johnston
0f31e924a6 Transparent <For/> 2022-12-23 09:34:47 -05:00
Jose Quesada
c89930aed0 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-23 08:19:15 -06:00
Greg Johnston
3d160ed152 Merge in changes to leptos_reactive from main 2022-12-23 09:19:04 -05:00
Jose Quesada
8037915294 reintroduced panic in DynChild 2022-12-23 08:19:02 -06:00
Greg Johnston
b62568b8a4 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-23 08:59:23 -05:00
Jose Quesada
a5d7563a67 fixed DynChild panicking when expected text is not there 2022-12-23 07:54:29 -06:00
Ben Wishovich
fbacfc787c Add missing port to Websockets code 2022-12-22 20:56:47 -08:00
Greg Johnston
0bf52c95bb Make sure --debug is noted in examples so hydration matches 2022-12-22 21:24:36 -05:00
Greg Johnston
89aa02af19 Update counter example 2022-12-22 21:21:17 -05:00
Greg Johnston
21af940c61 Merge pull request #175 from ultrasaurus/counter-example
fix warning, set initial value of counter
2022-12-22 21:08:49 -05:00
Greg Johnston
46c939ba28 Relax all the Debug trait bounds on various types in leptos_reactive 2022-12-22 21:07:38 -05:00
Greg Johnston
d158c34d24 Transition back to Transition in hackernews 2022-12-22 20:55:38 -05:00
Greg Johnston
42eef284e6 Fix Transition in new hydration model 2022-12-22 20:55:17 -05:00
Greg Johnston
6cf5d0a403 <Route element=... => view=... 2022-12-22 20:54:52 -05:00
Greg Johnston
79ac501302 Make <Suspense/> properly reactive again (i.e., shows fallback between states) 2022-12-22 20:45:51 -05:00
Greg Johnston
fdf17af7ab Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-22 20:21:17 -05:00
Greg Johnston
ac16d34985 Fix scoping issue by manually creating Component in Suspense 2022-12-22 20:21:14 -05:00
Jose Quesada
aa9f8f24b0 renamed element to view on <Route /> and RouteDefinition 2022-12-22 17:41:01 -06:00
Jose Quesada
d2ba8f5d46 exporting everything from matching 2022-12-22 17:30:30 -06:00
Greg Johnston
7c25cd9200 Use #[component] macro for core components, deleting leptos_core package 2022-12-22 16:46:48 -05:00
Jose Quesada
34b4917837 updated component doc formatting 2022-12-22 13:10:41 -06:00
Ben Wishovich
ac489e7523 Who let me near the computer before coffee? 2022-12-22 08:42:16 -08:00
Ben Wishovich
0909f60e55 Remove redundant env check and add path option to get_configuration() 2022-12-22 08:39:04 -08:00
Ben Wishovich
5ec76682a7 Fix Websockets Code and re-enable optimizations in tailwind. Remove watch as a param 2022-12-21 23:54:48 -08:00
Ben Wishovich
428999fd14 Updated all the examples to use the new leptos_options, and make cargo-leptos porting easy. Refactored the Tailwind example to bring it closer to leptos norms 2022-12-21 23:08:39 -08:00
Greg Johnston
ce84632c39 Update NodeRef to be generic over typed HTML elements 2022-12-21 21:15:48 -05:00
Greg Johnston
351389c2bf Correct types in SSR 2022-12-21 20:47:30 -05:00
Greg Johnston
532f5c5b83 Add types for HTML elements 2022-12-21 20:37:15 -05:00
Ben Wishovich
0d314224c9 Make tests pass, and do small tweaks/cleanup 2022-12-21 11:51:29 -08:00
Ben Wishovich
b4897f7a61 Fix dumb typos and add an option for an id to Stylesheet 2022-12-21 10:15:42 -08:00
Sarah Allen
49e93278b5 info about how to set up nightly -> README 2022-12-21 07:19:43 -08:00
Sarah Allen
cd59bf5a10 fix warning, set initial value of counter 2022-12-21 07:11:15 -08:00
Greg Johnston
66ac7d2a9d Fix hydration of <Routes/> 2022-12-21 07:58:26 -05:00
Greg Johnston
ae82395100 Remove some hydration key element increments 2022-12-21 07:58:08 -05:00
Greg Johnston
e57b6e0ccf Tidy up <Suspense/> 2022-12-21 07:57:44 -05:00
Greg Johnston
2f218e7428 Small changes to examples 2022-12-21 07:56:33 -05:00
Ben Wishovich
f2e9d6f4c3 More small tweaks to support config 2022-12-20 17:56:38 -08:00
Ben Wishovich
ee379bb405 Add errors to leptos_config and more changes to support beta 2022-12-20 12:14:42 -08:00
Ben Wishovich
d5fbeb9474 WIP Implementation of expanded LeptosOptions, which interop with the cargo-leptos beta and allow configuration of Leptos. Adds id option to <Stylesheet/> 2022-12-20 12:14:05 -08:00
Greg Johnston
7ca131c5b8 Work on hydration examples 2022-12-19 22:45:12 -05:00
Greg Johnston
79712ac4ef Fixes for <Suspense/> hydration 2022-12-19 22:45:00 -05:00
Greg Johnston
065d6b3c19 Fix workspace 2022-12-19 22:44:41 -05:00
Greg Johnston
9a2035f1e1 Relocate view-tests into leptos_dom 2022-12-19 20:11:25 -05:00
Greg Johnston
df8e50e85a Update TodoMVC example 2022-12-19 20:10:15 -05:00
Greg Johnston
58748af63b Fix _ref API in macro 2022-12-19 20:10:09 -05:00
Greg Johnston
36099c19c3 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-19 16:25:26 -05:00
Greg Johnston
8be33ccd7c Updating todo-app-sqlite example (todo: fix hydration) 2022-12-19 16:25:24 -05:00
Greg Johnston
d6920847ca Fix tests in counter example 2022-12-19 16:14:46 -05:00
Jose Quesada
f2553c117b changed from using <template /> to using custom element names and fixed EachItem on release 2022-12-19 08:57:09 -06:00
Greg Johnston
c63c8728a7 Clear warnings in router example 2022-12-19 07:41:50 -05:00
Greg Johnston
557bd25e2c Clear warnings 2022-12-19 07:39:30 -05:00
Greg Johnston
5ee8b20770 Clear warnings 2022-12-19 07:35:18 -05:00
Greg Johnston
da4b46e359 Clear warnings and improve #[cfg] readability 2022-12-19 07:34:10 -05:00
Greg Johnston
51b0ec3204 Clear warnings in view macro 2022-12-19 07:26:31 -05:00
Greg Johnston
c103c8f05b Suppress warnings about unused Scope variable in components 2022-12-19 07:22:25 -05:00
Greg Johnston
83c8f8b0cb Clear warnings in #[component] macro 2022-12-19 07:20:55 -05:00
Jose Quesada
eccbc424a2 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-18 16:52:23 -06:00
Jose Quesada
9d370776d2 printing html as it is being streamed to client 2022-12-18 16:52:12 -06:00
Greg Johnston
fc8921445e Update parent-child example 2022-12-18 17:12:06 -05:00
Greg Johnston
c635adb426 Fix Suspense & Transition, hopefully for last time (lol) 2022-12-18 17:01:56 -05:00
Greg Johnston
a845bf12e6 Clear warnings 2022-12-18 16:27:19 -05:00
Greg Johnston
eb573bf242 Remove HydrationKey from leptos_reactive 2022-12-18 16:23:04 -05:00
Greg Johnston
e8aaa77160 Remove now-unused hydration stuff from Scope 2022-12-18 16:20:44 -05:00
Greg Johnston
c0a407b0cd Fix --release builds 2022-12-18 16:15:18 -05:00
Jose Quesada
d79d4c4f86 fixed Fragment::lazy that should take `FnOnce 2022-12-18 13:29:46 -06:00
Greg Johnston
3195ab4ffc Get Suspense/Transition hydration working 2022-12-18 07:38:51 -05:00
Greg Johnston
80287f7a61 Merge pull request #174 from nim65s/main
Fix example tailwind
2022-12-17 19:43:52 -05:00
Guilhem Saurel
218faed341 Fix example tailwind
fix:
╰─>$ cargo leptos watch
Error: at `…/cargo-leptos-0.0.9/src/main.rs@104:58`

Caused by:
    no css/sass/scss file found at: "style/output.css"
2022-12-17 23:33:18 +01:00
Jose Quesada
d071a7c1e0 added HydrationCtx helper methods for forcebly adding leptos-hk, only helpers though, still need to update component lookup logic as well as element and template creation to include these 2022-12-17 12:38:40 -06:00
Jose Quesada
234e1cda4e Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-17 11:57:25 -06:00
Jose Quesada
e140549755 now removing id and leptos-hk from elements 2022-12-17 11:57:14 -06:00
Greg Johnston
df41e4dbc2 FIxes for Suspense/Hydration 2022-12-17 08:46:09 -05:00
Greg Johnston
9c6aaed0a8 Fix issue of <Routes/> mismatch 2022-12-17 08:28:22 -05:00
Greg Johnston
eaf4bbb068 Merge pull request #173 from benwis/ssr-headers
Allow Headers and Status to be set by components and Server Fns during initial SSR Load
2022-12-17 07:04:32 -05:00
Ben Wishovich
186e2454b0 Fix DBs 2022-12-16 17:37:17 -08:00
Ben Wishovich
6fa15a5584 Cleanup of testing files 2022-12-16 17:35:32 -08:00
Jose Quesada
aa71e1f66c Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-16 16:38:06 -06:00
Jose Quesada
ae16c2f96d prepending :: to leptos imports 2022-12-16 16:37:47 -06:00
Greg Johnston
4e8ad641ec Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-16 17:35:57 -05:00
Greg Johnston
64c29b1787 Remove unused import 2022-12-16 16:43:07 -05:00
Greg Johnston
df517ea9bb Add transition support 2022-12-16 16:42:27 -05:00
Ben Wishovich
2d289dd2b6 Actix version, but the issue is the same 2022-12-16 13:18:35 -08:00
Greg Johnston
702a785ca0 Fix context tests 2022-12-16 15:28:10 -05:00
Jose Quesada
abc117b9bf annotated For with #[component] 2022-12-16 14:13:51 -06:00
Greg Johnston
4823e0eb8d Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-16 12:17:49 -05:00
Greg Johnston
d65fde1ed4 Fix Link in SSR 2022-12-16 12:17:41 -05:00
Jose Quesada
6cfd2ba04e added prop docs to props builder 2022-12-16 08:51:07 -06:00
Jose Quesada
cd178c5c85 using format_ident instead of Ident::new 2022-12-16 08:25:52 -06:00
Jose Quesada
5a44f9eb4b Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-16 07:57:00 -06:00
Jose Quesada
688b0a6b73 started fine-tunning view macro spans 2022-12-16 07:30:13 -06:00
Greg Johnston
ef84d77e12 Merge branch 'main' of https://github.com/gbj/leptos 2022-12-16 07:20:59 -05:00
Greg Johnston
924b632fd3 Improve docs for provide_context and use_context 2022-12-16 07:20:54 -05:00
Ben Wishovich
2658e158df HERE BE DRAGONS 2022-12-15 22:31:47 -08:00
Ben Wishovich
21274c08bf Hmmmm 2022-12-15 22:07:11 -08:00
Greg Johnston
b83cf4dc51 Clean up Suspense SSR 2022-12-15 21:58:11 -05:00
Greg Johnston
1826d4bab2 Remove extra logging 2022-12-15 21:56:11 -05:00
Greg Johnston
e6e71cb8e6 Remove extra logging 2022-12-15 21:55:21 -05:00
Greg Johnston
01252b841d Fix <Suspense/> SSR 2022-12-15 21:54:43 -05:00
Greg Johnston
c6d30a710a FIx issues I introduced to SSR while logging this 2022-12-15 21:04:55 -05:00
Greg Johnston
fefca82d16 Minimal tracing to show order of rendering 2022-12-15 20:56:52 -05:00
Greg Johnston
a253d224ac Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-15 20:18:44 -05:00
Greg Johnston
04f331d444 Fix missing HTML 2022-12-15 20:18:41 -05:00
Ben Wishovich
2fb3515e62 Cursed, it is 2022-12-15 16:03:07 -08:00
Ben Wishovich
7a8b08d149 Broken in a new way 2022-12-15 15:57:41 -08:00
Ben Wishovich
0bc29b5f26 Closer maybe? 2022-12-15 14:12:54 -08:00
Ben Wishovich
f9bda65dbe WIP impl of SSR Header/Status setting 2022-12-15 13:14:02 -08:00
Jose Quesada
a591d54a22 changed router to directly return children, rather than a closure to not break tracing continuity 2022-12-15 13:53:39 -06:00
Jose Quesada
3e508b16f3 impl #[component(transparent)] 2022-12-15 13:40:58 -06:00
Jose Quesada
5603fac109 ported Route 2022-12-15 13:07:09 -06:00
Jose Quesada
8adf9108c5 ported Routes 2022-12-15 13:00:53 -06:00
Jose Quesada
610e38a967 fixed Coutlet from being a double component 2022-12-15 12:52:46 -06:00
Jose Quesada
34697b74a0 fixed form components to take children(cx) directly instead of a closure 2022-12-15 12:51:43 -06:00
Jose Quesada
0a8b516182 ported A 2022-12-15 12:50:00 -06:00
Jose Quesada
5405dcd09d ported MultiActionForm 2022-12-15 12:40:41 -06:00
Jose Quesada
1aaacbaf5b ported ActionForm 2022-12-15 12:37:19 -06:00
Jose Quesada
ce9aec2520 started porting router to #[component] 2022-12-15 12:31:53 -06:00
Jose Quesada
422233eecf removed some HydrationCtx things and improved tracing for DynChild 2022-12-15 12:05:17 -06:00
Jose Quesada
3b99d2d4fd added tracing support to component macro 2022-12-15 12:01:16 -06:00
Jose Quesada
9eadac9f2c added HydrationCtx helpers and fixed a couple bugs with the hydration example 2022-12-15 10:04:44 -06:00
Greg Johnston
416e1a617b Change start to hydrate in example 2022-12-15 08:39:19 -05:00
Greg Johnston
1b0aa4d903 Disable macro SSR until I've added IDs 2022-12-15 08:36:46 -05:00
Greg Johnston
01013b00e5 Implement classes in SSR macro path 2022-12-15 07:56:31 -05:00
Greg Johnston
3ef64bd372 <Suspense/> streaming and hydration issue 2022-12-14 23:18:54 -05:00
Greg Johnston
c463579faa Round 1 of next_hydration_key() 2022-12-14 20:38:37 -05:00
Greg Johnston
67de5685bb Merge pull request #167 from benwis/axum-context
Give Axum access to Request and allow server functions to set status/headers/cookies
2022-12-14 15:47:54 -05:00
Ben Wishovich
8a85d4261a Fix Todo DB 2022-12-14 11:20:53 -08:00
Jose Quesada
218c4d3c90 moved body back inside itself to allow forwarding attributes 2022-12-14 12:57:43 -06:00
Ben Wishovich
90849cc6e3 Add working example of Actix/Axum Header and Status Setting 2022-12-14 10:55:05 -08:00
Jose Quesada
5f95776a08 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-14 12:24:16 -06:00
Jose Quesada
adee33a08e initial impl of #[prop()] 2022-12-14 12:15:41 -06:00
Greg Johnston
e3e0460371 Disable SSR macr until node ID generation is done 2022-12-14 10:57:37 -05:00
Greg Johnston
6e4448dae6 SSR work with missing node IDs 2022-12-14 10:56:48 -05:00
Greg Johnston
fee0f5490b Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-14 09:06:20 -05:00
Greg Johnston
e1836af6bd Fix .wasm location in integration 2022-12-14 09:06:10 -05:00
Jose Quesada
b37a36a003 allowing clippy lint for too many arguments on components 2022-12-14 07:34:31 -06:00
Greg Johnston
e865f609ee Merge pull request #166 from gbj/component-macro-docs
Add more entry-level docs for `#[component]` macro
2022-12-14 07:49:33 -05:00
Greg Johnston
621122adf7 Fix Suspense/Transition SSR 2022-12-14 07:12:43 -05:00
Greg Johnston
f6acecd3ad Fix Wasm import URL in integrations 2022-12-14 07:12:36 -05:00
Greg Johnston
f17c7fdb90 Remove duplicated window_event_listener 2022-12-14 07:00:56 -05:00
Greg Johnston
21178b1682 Correct definitions of is_browser and is_server 2022-12-14 06:57:35 -05:00
Greg Johnston
1c8b640855 Update #[component] docs 2022-12-14 06:44:14 -05:00
Ben Wishovich
9f97497e48 Working impl of Request access and Response cookies for Axum 2022-12-13 22:07:15 -08:00
Ben Wishovich
70f2b3b4d3 More fiddling, still no dice 2022-12-13 16:05:31 -08:00
Ben Wishovich
181a15cf66 WIP axum acces to request 2022-12-13 15:23:47 -08:00
Jose Quesada
a7a35857bb now tracking scope name 2022-12-13 14:33:34 -06:00
Jose Quesada
caa919b257 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-13 14:15:42 -06:00
Jose Quesada
4c123884de reverted to redeclaring the component fn within itself 2022-12-13 14:15:23 -06:00
Greg Johnston
5e06eb1a99 Correct use of cx 2022-12-13 15:14:41 -05:00
Greg Johnston
cc0bf20c9d Use the correct identifier for cx here 2022-12-13 15:06:21 -05:00
Jose Quesada
5aab8e40c2 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-13 13:24:06 -06:00
Jose Quesada
eeaccfc815 moved fn block into Component::new 2022-12-13 13:23:51 -06:00
Greg Johnston
cac1187346 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-13 14:21:06 -05:00
Greg Johnston
4134d2f924 Working on router example 2022-12-13 14:20:58 -05:00
Greg Johnston
621976c92c Add correct import for doctest 2022-12-13 14:14:04 -05:00
Jose Quesada
39e809f686 initial impl of component macro with inline doc comments and TypedBuilder overrides 2022-12-13 12:44:30 -06:00
Greg Johnston
b2d7ad2afd Fix a couple issues with intra-doc links 2022-12-13 13:10:04 -05:00
Greg Johnston
73b21487b9 Add more entry-level docs for #[component] macro 2022-12-13 13:06:37 -05:00
Greg Johnston
896812c8d6 Merge pull request #165 from Gentle/update_returning
update_returning handlers
2022-12-13 12:54:40 -05:00
Jose Quesada
286c95136f Merge branch 'leptos_dom_v2' into leptos_dom_v2_component 2022-12-13 07:38:51 -06:00
Greg Johnston
5ca169ac06 Properly handle Scope when creating component children 2022-12-13 07:42:14 -05:00
Greg Johnston
8efb28826f Properly set hydration key 2022-12-12 21:17:51 -05:00
Greg Johnston
10799c33b7 Properly dispose 2022-12-12 21:17:38 -05:00
Greg Johnston
657de9df33 Remove log 2022-12-12 20:57:18 -05:00
Greg Johnston
069fc88042 Update SSR support for Suspense/Transition 2022-12-12 20:56:19 -05:00
Greg Johnston
92335989b7 Don't overwrite MetaContext from integration 2022-12-12 20:55:57 -05:00
Greg Johnston
58d2ce113d Use Scope-based hydration key generation 2022-12-12 20:55:41 -05:00
Greg Johnston
e499c88288 Consolidating hydration key generation 2022-12-12 20:55:28 -05:00
Ramon Klass
fea462c90a update_returning handlers 2022-12-13 02:19:58 +01:00
Jose Quesada
a75cbee133 started working on component macro 2022-12-12 18:33:12 -06:00
Jose Quesada
99ff73c721 applied fix per gbj's suggested 2022-12-12 16:23:15 -06:00
Jose Quesada
2c9eff3659 impl IntoView for all std types that made sense 2022-12-12 14:45:10 -06:00
Jose Quesada
ce5355d73f impl IntoView for `Vec<impl IntoView> 2022-12-12 13:52:41 -06:00
Jose Quesada
582cd7d729 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-12 13:39:57 -06:00
Jose Quesada
e2ef293d19 added IntoFragment trait for all IntoIterator and also impl FromIterator for Fragment 2022-12-12 13:39:41 -06:00
Greg Johnston
b06a4ba805 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-12 13:40:13 -05:00
Greg Johnston
6b6c54e8ff Updating hackernews example 2022-12-12 13:40:05 -05:00
Greg Johnston
8a0e56aff5 Properly namespace Fragment when used 2022-12-12 13:39:50 -05:00
Greg Johnston
1804a65857 Merge in updates to meta package 2022-12-12 13:39:30 -05:00
Greg Johnston
035f929d3b Merge class prop back into A component 2022-12-12 13:39:19 -05:00
Jose Quesada
0b11a8dda6 fixed compilation on non-CSR targets 2022-12-12 12:26:11 -06:00
Jose Quesada
5881fb9064 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-12 12:18:29 -06:00
Jose Quesada
9dbbb26100 made is_server and helpers const fn and added View::into_html_element helper 2022-12-12 12:18:15 -06:00
Greg Johnston
9c0d813697 Resolve issue with scope disposal panicking because it can't find runtime (because runtime already dropped) 2022-12-12 10:25:20 -05:00
Greg Johnston
4a1d16b641 Properly reset ID in streaming 2022-12-12 10:24:55 -05:00
Greg Johnston
c4eeb4f39f Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-12 09:49:22 -05:00
Greg Johnston
37ab7b34f9 Fix imports when in SSR mode so we don't run wasm-bindgen code 2022-12-12 09:49:15 -05:00
Greg Johnston
fcae17eab7 Streamline streaming SSR 2022-12-12 09:48:45 -05:00
Greg Johnston
c4cc3e944b Merge in changes from main 2022-12-12 09:26:46 -05:00
Greg Johnston
c481e465b0 Update counter-isomorphic 2022-12-12 09:26:13 -05:00
Greg Johnston
073bd759b0 Add .gitignore 2022-12-12 09:25:57 -05:00
Greg Johnston
88435af844 Update counter-isomorphicexample 2022-12-12 09:25:47 -05:00
Jose Quesada
ff21f38626 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-12 07:29:51 -06:00
Jose Quesada
9bc8492245 removed impl of IntoView for &str and replaced with &'static str for Cow<'static, str> opt 2022-12-12 07:29:35 -06:00
Greg Johnston
2389cec5f7 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-11 20:21:35 -05:00
Greg Johnston
86d5f4c2e4 Update <For/> in example 2022-12-11 20:21:07 -05:00
Jose Quesada
811449d664 stopped DynChild from panicking when nested DynChild run within the same signal trigger but the parent runs before this child 2022-12-11 17:36:19 -06:00
Greg Johnston
109863c59a Update SSR benchmark code to new APIs 2022-12-11 17:42:15 -05:00
Greg Johnston
b9e8777bb1 Update <For/> API 2022-12-11 17:35:46 -05:00
Jose Quesada
d44c7f121b remove Transition DynChild workaround 2022-12-11 13:37:45 -06:00
Jose Quesada
9b1c4e42bd added missing generic and removed workaround for Suspense DynChild 2022-12-11 13:33:11 -06:00
Jose Quesada
ff026ea953 addressed clippy lints in release mode 2022-12-11 13:27:52 -06:00
Jose Quesada
9eb1f2fdf8 addressed clippy lints 2022-12-11 13:22:01 -06:00
Jose Quesada
06538ba021 fixed DynChild when changing from Text to anything else 2022-12-11 13:06:54 -06:00
Jose Quesada
14c6dcf902 now surrounding View::Text with quotes 2022-12-11 12:57:54 -06:00
Jose Quesada
a15dedb82d impl new fmt::Debug repr for View 2022-12-11 12:43:58 -06:00
Greg Johnston
43ffa1bcd7 Use Fn() -> Fragment for component children, and update router and Suspense/Transition 2022-12-10 22:12:08 -05:00
Greg Johnston
d30de9abce Add Transparent type to pass arbitrary data inside a View 2022-12-10 22:11:39 -05:00
Greg Johnston
f459253cdb Clear warning here and add explanation 2022-12-10 21:05:13 -05:00
Greg Johnston
a53f7ccdb7 Update Suspense and Transition with new impl IntoView pattern 2022-12-10 19:51:41 -05:00
Greg Johnston
b7bd4fc69c Update Counters example 2022-12-10 19:51:30 -05:00
Greg Johnston
9d43eb5503 Tweak handling of component children 2022-12-10 19:42:08 -05:00
Greg Johnston
335c040702 Implement IntoView for same set of primitive types 2022-12-10 19:33:56 -05:00
Greg Johnston
a4e5bf03d8 Start implementing IntoView for primitives 2022-12-10 19:28:28 -05:00
Greg Johnston
90de653a60 Concrete return types work 2022-12-10 19:28:11 -05:00
Greg Johnston
359feebccf Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-10 19:21:51 -05:00
Greg Johnston
6c29d85b8d Remove into_view in view and component macros 2022-12-10 19:21:46 -05:00
Jose Quesada
315407b866 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-10 15:32:51 -06:00
Jose Quesada
d22fa3c5e7 removed IntoChild 2022-12-10 15:32:36 -06:00
Greg Johnston
6d24af7748 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-10 16:22:55 -05:00
Greg Johnston
18bd2162cf Docs in component macro 2022-12-10 16:21:58 -05:00
Jose Quesada
74ea50a293 fixed Component::new to take anything that impl IntoView 2022-12-10 13:50:05 -06:00
Greg Johnston
4a9f906571 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-10 14:09:43 -05:00
Greg Johnston
4b970b3f1c Fix rerendering issue 2022-12-10 14:06:49 -05:00
Greg Johnston
6db086c0a6 Meant to delete this, not comment it out 2022-12-10 14:06:42 -05:00
Greg Johnston
a7da8232a7 I was wrong -- these will be automatically disposed by the parent scope in the correct order, and actually shouldn't be done manually 2022-12-10 14:06:18 -05:00
Jose Quesada
a5f868915a added trait for converting impl AsRef<web_sys::Element> to HtmlElement<AnyElement> 2022-12-10 12:16:08 -06:00
Jose Quesada
237bacc2da addressed all clippy lints 2022-12-10 10:50:01 -06:00
Jose Quesada
e09f5665ca Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-10 09:54:56 -06:00
Jose Quesada
11720302a2 addressed all clippy lints for web targets 2022-12-10 09:54:49 -06:00
Jose Quesada
e097ec84c2 started addressing clippy lints and fixed an undiscovered bug 2022-12-10 08:40:24 -06:00
Greg Johnston
bcb130deca Working on router 2022-12-10 09:15:05 -05:00
Greg Johnston
c4af033f2c Remove logging 2022-12-10 09:12:11 -05:00
Greg Johnston
5bdd150347 Get router working with new renderer 2022-12-10 08:32:58 -05:00
Greg Johnston
f9cc57acb9 Fix attributes in view macro 2022-12-10 08:32:30 -05:00
Greg Johnston
000d796149 Update router example 2022-12-10 08:32:19 -05:00
Greg Johnston
a7c16c9b09 Implement PartialEq and Eq for View 2022-12-10 07:37:07 -05:00
Greg Johnston
ad01d69540 <Suspense/> and <Transition/> 2022-12-09 22:52:30 -05:00
Greg Johnston
7959f5b324 Add signal helpers from main that are needed for <Transition/> 2022-12-09 22:52:14 -05:00
Greg Johnston
46e77d72ea Add transition 2022-12-09 22:23:42 -05:00
Greg Johnston
1b8db4d4f4 "Implement Clone on View and its affiliates. Necessary for <Transition/> and some routing features. No significant changes needed, every type involved could already derive Clone. 2022-12-09 22:17:26 -05:00
Greg Johnston
7264d902c6 RIP map_keyed and old <For/> component 2022-12-09 22:07:07 -05:00
Jose Quesada
8017b416fb Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-09 18:58:58 -06:00
Jose Quesada
dd16890021 Component now creating child scope, forgot about this 2022-12-09 18:58:38 -06:00
Jose Quesada
a17651fe02 removed the workspace override 2022-12-09 18:00:06 -06:00
Greg Johnston
ba34a9644e Work on Suspense 2022-12-09 18:27:32 -05:00
Jose Quesada
094492f076 impl IntoChild for tuples up to 26 in size 2022-12-09 17:13:37 -06:00
Jose Quesada
6d5994f72e removed TopoId 2022-12-09 17:08:11 -06:00
Jose Quesada
641a064200 removed IntoEach until we can come up with a better game plan 2022-12-09 17:04:32 -06:00
Jose Quesada
c83f29be1b fix DynChild saving it's old child, rather than the new one 2022-12-09 16:46:02 -06:00
Jose Quesada
bd3cc0b5ec fix DynChild trying to render old child rather than new one 2022-12-09 16:17:37 -06:00
Greg Johnston
0b448daf3a Fix SimpleCounter example in tests 2022-12-09 14:58:53 -05:00
Greg Johnston
f6eceaeaf9 Update counters exaple 2022-12-09 14:56:50 -05:00
Greg Johnston
9a114eb595 Avoid name conflicts between functions to create elements and local variables 2022-12-09 14:36:25 -05:00
Greg Johnston
c01dba5138 Merge pull request #160 from gbj/component-documentation
Allows documenting `Component` and `ComponentProps` in a single doc comment
2022-12-09 14:27:36 -05:00
Greg Johnston
1929f2d8b2 Merge pull request #161 from gbj/docs-improvements
Docs improvements
2022-12-09 13:56:18 -05:00
Greg Johnston
50b0fe157a Fix example test 2022-12-09 13:34:35 -05:00
Greg Johnston
dc7f44933c Add cargo-leptos to Readme 2022-12-09 13:28:26 -05:00
Greg Johnston
64a5d75ec4 .into() calls were interfering with components that have generic props 2022-12-09 13:09:02 -05:00
Greg Johnston
b56dde9a6d Add working Tailwind example per issue #147 2022-12-09 13:05:20 -05:00
Greg Johnston
74ec8925dc Additional documentation for issue #156 2022-12-09 12:41:17 -05:00
Greg Johnston
baf3cc8712 Correct imports 2022-12-09 12:36:33 -05:00
Greg Johnston
23777ad67b Use leptos reexport of typed-builder crate 2022-12-09 12:30:21 -05:00
Jose Quesada
1ee9c2432b impl IntoView for tuples of up to 26 fields as well as for (Scope, T) 2022-12-09 11:29:46 -06:00
Jose Quesada
b0c27c48f6 updated example to work with new Each 2022-12-09 10:49:15 -06:00
Jose Quesada
c74a8274f2 removed child scope creation within Each 2022-12-09 10:44:05 -06:00
Jose Quesada
2ceb7f8934 fixed Fragment which would try mounting it's children while hydrating 2022-12-09 10:03:08 -06:00
Jose Quesada
16af593277 added render_to_string entry point and fixed bug where id counter would not be reset on every server render call 2022-12-09 09:34:25 -06:00
Jose Quesada
51c8d85528 custom user id's on HtmlElement is now supported during hydration 2022-12-09 09:15:37 -06:00
Jose Quesada
4ffc53a1dc not panicking when elements/components cannot be found 2022-12-09 08:47:53 -06:00
Jose Quesada
b7eeba77a0 fixed DynChild on release to prevent it merging with surrounding text 2022-12-09 08:25:39 -06:00
Jose Quesada
a8fb2720b9 removed a sneaky c that was in the SSR id generation for components, as well as fixed an extra id call count that wasn't supposed to be there 2022-12-08 22:40:49 -06:00
Jose Quesada
a50f1c58f7 fixed Each optimizations 2022-12-08 20:38:59 -06:00
Jose Quesada
6528aadb90 removed debug statement 2022-12-08 19:18:23 -06:00
Jose Quesada
dcd9842fca Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-08 18:42:55 -06:00
Jose Quesada
5a976525c0 fixed Each moving items it did not need to move 2022-12-08 18:42:36 -06:00
Greg Johnston
b8559d4335 Transition counter example to use View 2022-12-08 19:33:01 -05:00
Greg Johnston
eb40f9f7c7 Remove leptos_dom/ssr dependencies 2022-12-08 19:32:46 -05:00
Greg Johnston
08be1ba622 Fix warnings 2022-12-08 19:28:23 -05:00
Greg Johnston
605398bcea Only use default for Option<T> 2022-12-08 19:27:45 -05:00
Greg Johnston
d0fa9b89bf Remove my logs 2022-12-08 19:25:50 -05:00
Greg Johnston
fbfd1a4f60 Fix other dependencies on leptos_dom/csr and leptos_dom/hydrate 2022-12-08 19:24:36 -05:00
Jose Quesada
21716ea59d fixed panic on DynChild for double taking an option 2022-12-08 18:15:57 -06:00
Jose Quesada
e641108ed3 fixed error compiling 2022-12-08 18:01:06 -06:00
Jose Quesada
c3b4945c7e removed all cfgs that depend on anything but web and wasm32 2022-12-08 17:56:52 -06:00
Jose Quesada
95c535290d Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-08 17:48:45 -06:00
Jose Quesada
6af0b1a8ed hydration is now determained at runtime startup 2022-12-08 17:48:30 -06:00
Greg Johnston
9928abf36d Fix closing-node creation in Each in release 2022-12-08 18:45:27 -05:00
Greg Johnston
f0257222f8 Fix cx injection in macro 2022-12-08 18:29:44 -05:00
Greg Johnston
135317b7b8 Method, not a field 2022-12-08 18:26:44 -05:00
Jose Quesada
6b24135070 fixed subtle bug when hydrating from a text node would cause DynChild to not unmount correctly 2022-12-08 17:00:55 -06:00
Jose Quesada
e08808c2ab fixed SSR compilation errors 2022-12-08 16:13:12 -06:00
Greg Johnston
aca2c131d4 Add the ability to document Component and ComponentProps in a single doc comment. 2022-12-08 17:08:54 -05:00
Jose Quesada
a932f72a4f DynChild now creating child scopes 2022-12-08 16:07:44 -06:00
Jose Quesada
75befde788 now creating child scopes for Each 2022-12-08 15:17:12 -06:00
Greg Johnston
3d10bbb0c6 Merge pull request #159 from benwis/dashes
Replace _ with - for KDL files
2022-12-08 13:15:21 -05:00
Ben Wishovich
8d325fce5c Replace _ with - for KDL files 2022-12-08 10:08:04 -08:00
Jose Quesada
adac34790e now creating child scopes for Each items, still not cleaning them up, however 2022-12-08 11:50:22 -06:00
Jose Quesada
838d0d27c9 fixed DynChild not removing the text generated on SSR 2022-12-08 11:10:34 -06:00
Jose Quesada
d29d29c1d4 fixed .into_view(cx) calling order to match between SSR and CSR 2022-12-08 10:41:28 -06:00
Jose Quesada
61e206c227 corrected DynChild to now mount children on SSR 2022-12-08 09:19:00 -06:00
Jose Quesada
70ae60d4d5 fixed broken compilation 2022-12-08 08:56:53 -06:00
Greg Johnston
7e457ee202 Merge pull request #157 from akesson/integration-html-updates
Integration html updates
2022-12-08 08:05:25 -05:00
hakesson
bb282189c3 Add preload of js and wasm 2022-12-08 08:11:15 +01:00
hakesson
2694d2e93c Add missing init param 2022-12-08 08:10:56 +01:00
Greg Johnston
56457bc3ad Generate HydrationKey with Scope 2022-12-07 15:57:53 -05:00
Greg Johnston
45395fe580 Fix off-by-one issue 2022-12-07 15:46:09 -05:00
Jose Quesada
3a90ed6c21 added debug aids to find the off-by-one error 2022-12-07 12:33:39 -06:00
Jose Quesada
55b691e1b0 marker hydration fixed, but we have an off-by-one error on id generation 2022-12-07 12:05:12 -06:00
Jose Quesada
c9b57ffa85 changed the value to bind to another input while I fix text 2022-12-07 10:43:10 -06:00
Jose Quesada
c239716170 updated the example to work with hydartion 2022-12-07 10:04:54 -06:00
Jose Quesada
46ef1bcf5d initial impl of eager hydration 2022-12-07 09:36:36 -06:00
Jose Quesada
5ac06251d4 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-07 07:24:53 -06:00
Jose Quesada
395cfe6bf1 fixed SSR and CSR cfg features 2022-12-07 07:24:35 -06:00
Greg Johnston
9d950b97ff Better error message for RouterIntegrationContext 2022-12-07 07:52:01 -05:00
Greg Johnston
f6a299ae3c Merge pull request #154 from gbj/fix-component-siblings-in-hydration
Fix issue #109
2022-12-07 00:06:48 -05:00
Greg Johnston
963ff85a5f Get basic SSR example working 2022-12-06 23:04:48 -05:00
Greg Johnston
dcbdbc8925 <template/> doesn't work as a self-closing tag 2022-12-06 23:03:33 -05:00
Greg Johnston
1ba602ec47 Fix issue #109 2022-12-06 22:31:54 -05:00
Jose Quesada
c290d1e9d6 started impl hydration for HtmlElement 2022-12-06 20:14:35 -06:00
Greg Johnston
1f3dde5b4a Fix Hackernews CSS 2022-12-06 19:22:29 -05:00
Greg Johnston
a65cd67db3 Fix name of Wasm export 2022-12-06 18:18:46 -05:00
Greg Johnston
bacd99260b Fix benchmarks 2022-12-06 18:18:38 -05:00
Jose Quesada
51e5c6ba62 fixed TopoId not having a sum field 2022-12-06 11:35:31 -06:00
Greg Johnston
2b726f1a88 Fix docs on props for each component 2022-12-06 11:42:47 -05:00
Jose Quesada
ee470b37bb removed starting_offset when calculating children ids 2022-12-06 10:26:19 -06:00
Jose Quesada
74c716e0f6 fixed attrs that start with an empty value from not having a space 2022-12-06 10:12:14 -06:00
Jose Quesada
00c25b5605 fixed EachItem not getting <template /> markers, as well as Unit 2022-12-06 09:55:02 -06:00
Jose Quesada
280f7a7735 removed cx param from all helper methods 2022-12-06 07:32:49 -06:00
Jose Quesada
f02405b649 fixed IntoProperty from disconnection from overwritten Scope 2022-12-06 07:24:21 -06:00
Jose Quesada
d6ef65daf6 fixed IntoClass from not disconnecting from overwritten Scope 2022-12-06 07:21:14 -06:00
Jose Quesada
98414ac192 removed overzelus use of Scope in Attribute 2022-12-06 07:15:39 -06:00
Jose Quesada
8b7728096a fixed IntoChild to not disconnect from overwritten Scope 2022-12-05 20:51:00 -06:00
Greg Johnston
aec289e384 Get SSR benchmarks running again 2022-12-05 20:34:29 -05:00
Greg Johnston
432eda8d6d Add some often-used helper functions 2022-12-05 20:00:27 -05:00
Greg Johnston
5c45538e9f Make necessary changes for stable support for router and meta 2022-12-05 18:55:03 -05:00
Greg Johnston
7f696a9ac4 support 2022-12-05 17:25:02 -05:00
Greg Johnston
bcd6e671f7 0.0.20 2022-12-05 17:23:22 -05:00
Greg Johnston
7a72f127de Stable compatibility 2022-12-05 17:18:17 -05:00
Greg Johnston
2ff5ec21c8 0.0.20 2022-12-05 16:25:16 -05:00
Greg Johnston
a1f94b609f Improvements to example to show off transitions and streaming 2022-12-05 16:17:47 -05:00
Greg Johnston
da5034da33 Bump versions after WASM-less fix 2022-12-05 16:17:29 -05:00
Greg Johnston
0c509970b5 Fix ability of server functions to work without WASM 2022-12-05 16:17:15 -05:00
Greg Johnston
d894c4dcf9 Merge branch 'main' of https://github.com/gbj/leptos 2022-12-05 16:10:33 -05:00
Greg Johnston
aa10ab861a Fix new cx-passing API for Attribute 2022-12-05 16:09:22 -05:00
Greg Johnston
870d8f3542 Different form for passing in cx 2022-12-05 16:07:25 -05:00
Greg Johnston
166df8d4c4 Merge changes to remove cx everywhere 2022-12-05 16:05:12 -05:00
Greg Johnston
666269539d Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-05 16:04:54 -05:00
Greg Johnston
0230b1ffa5 Deal w/ merge issues and get SSR working 2022-12-05 16:04:02 -05:00
Jose Quesada
3dd789f0c2 fixed IntoAttribute from disconnecting from it's overwritten Scope 2022-12-05 14:30:21 -06:00
Greg Johnston
dbb0fca1cb Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-05 15:12:09 -05:00
Greg Johnston
b8bd3bef13 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-05 15:11:17 -05:00
Jose Quesada
59f753cebb impl all the macro helper traits for (Scope, T) 2022-12-05 14:09:39 -06:00
Greg Johnston
d5f91e67a5 First pass at SSR 2022-12-05 15:09:04 -05:00
Greg Johnston
1b854ed787 Warn if you re-set a NodeRef 2022-12-05 14:24:33 -05:00
Jose Quesada
13f8006162 added HtmlElement::node_ref 2022-12-05 13:19:34 -06:00
Jose Quesada
b3d813d0c1 renamed IntoNode to IntoView and Node to View, and fixed broken doc links 2022-12-05 12:39:42 -06:00
Jose Quesada
1fbe8bd790 fixed the example to show undelegated 2022-12-05 12:28:14 -06:00
Jose Quesada
eba8af3b38 fixed event names and removed superfluous debug stmt 2022-12-05 12:23:53 -06:00
Jose Quesada
589f2585cc added small list of events that don't bubble 2022-12-05 11:43:18 -06:00
Jose Quesada
b69119f11f added all events I could find 2022-12-05 11:12:31 -06:00
Greg Johnston
dc15184781 Merge pull request #152 from benwis/cargo-leptos-updates
Add config crate and generate file for cargo-leptos to watch
2022-12-05 12:04:56 -05:00
Greg Johnston
f893dca39b This should handle the disposal correctly, when the parent scope disposes, instead of on Drop (which is immediate.) 2022-12-05 09:24:52 -05:00
Greg Johnston
64722604b5 Move Component::new() invocation inside the #[component] macro to allow for things like the <Route/> component 2022-12-05 08:45:27 -05:00
Greg Johnston
b6a90f154f Remove useless attempt at better Intellisense 2022-12-04 23:04:06 -05:00
Greg Johnston
2ef8032110 The event names shouldn't actually start with "on" — that's the HTML attribute form 2022-12-04 23:03:54 -05:00
Greg Johnston
3992febbfc Restored these events so they can be used, just typed as Event 2022-12-04 23:03:19 -05:00
Greg Johnston
982cec9507 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-04 22:59:57 -05:00
Greg Johnston
4a5b3b3cc5 Use new event system 2022-12-04 22:59:45 -05:00
Jose Quesada
18ff334f70 disabled non-existant web_sys event types 2022-12-04 21:38:23 -06:00
Jose Quesada
d2b4ae30d1 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-04 21:30:55 -06:00
Jose Quesada
abed797027 added HtmlElement::prop to the builder 2022-12-04 21:30:48 -06:00
Greg Johnston
a4ca863d42 Should insert the actual event type instead of MouseEvent! 2022-12-04 22:26:28 -05:00
Jose Quesada
6737413103 made Undelegated inner field public so users can just wrap any event with it to force it undelegated 2022-12-04 21:23:16 -06:00
Greg Johnston
33c3851d5b Fix fake assignment 2022-12-04 22:13:07 -05:00
Greg Johnston
7c298272d3 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-04 22:11:00 -05:00
Greg Johnston
71a2a24d09 Working components in view! macro 2022-12-04 22:10:56 -05:00
Jose Quesada
cffdc56062 added Custom event helper type for events not included 2022-12-04 20:45:58 -06:00
Jose Quesada
c29c15e1b7 removed on_delegated, as this can be done through Delegated<E>` type 2022-12-04 20:36:18 -06:00
Ben Wishovich
3200068ab3 Doc tweaks 2022-12-04 18:11:20 -08:00
Ben Wishovich
0a9da8d55e Add some doc comments, and change the behavior of the reload_port 2022-12-04 17:55:51 -08:00
Ben Wishovich
52ad546710 Update rest of the examples and make the tests pass 2022-12-04 17:25:03 -08:00
Ben Wishovich
f88d2fa56a Add socket_address option to configure the ip address and port to serve 2022-12-04 15:50:29 -08:00
Jose Quesada
fe417d50af Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-04 17:22:24 -06:00
Jose Quesada
cc538f8427 added more events 2022-12-04 17:22:03 -06:00
Ben Wishovich
f63cb02277 Commit WIP version of common config struct that writes a KDL file for cargo-leptos 2022-12-04 14:50:36 -08:00
Jose Quesada
07db7ae62b started the grooling process of adding typed events 2022-12-04 09:13:20 -06:00
Greg Johnston
4b363f9b33 0.0.3 for axum 0.6 compatibility 2022-12-03 22:12:17 -05:00
Greg Johnston
09d2a56672 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-03 21:29:22 -05:00
Greg Johnston
8ea7e20dfb Builder-compatible view! macro 2022-12-03 21:28:39 -05:00
Greg Johnston
02c982c80f Missing cfg causing non-CSR builds to break; I may have removed this accidentally or somethign 2022-12-03 21:27:53 -05:00
Jose Quesada
a5b157f14f uncommented (presumably) accidental comment of components import 2022-12-03 17:58:51 -06:00
Jose Quesada
5d439ceee8 fixed merge conflict 2022-12-03 16:52:57 -06:00
Jose Quesada
282ece2fab fixed Each when moving to take into account backshift 2022-12-03 16:50:29 -06:00
Greg Johnston
205abd4cbc Add _prop macro helper 2022-12-03 14:47:39 -05:00
Greg Johnston
fbb372e618 Add is_server and is_dev helper macros 2022-12-03 14:47:31 -05:00
Greg Johnston
b4679ea688 Fix NodeRef on stable 2022-12-03 14:28:33 -05:00
Greg Johnston
d2f68d8a0a Add helpers for simple logging 2022-12-03 14:22:19 -05:00
Greg Johnston
ebe872ca57 Add NodeRef 2022-12-03 14:21:42 -05:00
Greg Johnston
bce1ed8d67 Add NodeRef 2022-12-03 14:21:36 -05:00
Greg Johnston
a87ffd6d5c Make it possible for macro to specify event types automatically by reducing to one generic 2022-12-03 14:20:18 -05:00
Greg Johnston
c0d2dde53a _class helper for macro 2022-12-03 14:05:59 -05:00
Greg Johnston
cd93ecb5ab Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-03 13:43:14 -05:00
Greg Johnston
4beee7f924 Fix bounds check -- was panicking on remove because added_delta was -1 2022-12-03 13:43:05 -05:00
Jose Quesada
234260a784 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-03 12:29:45 -06:00
Jose Quesada
e82d4d492b revert EachItem lazy text fill 2022-12-03 12:29:28 -06:00
Greg Johnston
aa0271a493 Add _attr helper for macro 2022-12-03 13:06:15 -05:00
Greg Johnston
29db252411 Remove fill_if_text since eager now 2022-12-03 13:06:06 -05:00
Jose Quesada
aa5caaf4f1 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-03 10:38:47 -06:00
Jose Quesada
718b5f8ae1 forgot to fill child text nodes of EachItem 2022-12-03 10:34:36 -06:00
Greg Johnston
48e4e01e24 Fast path for Text -> Text. I think this is probably broken at the moment (if you replace Text with something else) but can fix 2022-12-03 11:29:53 -05:00
Greg Johnston
7948a1914a Fill Text node eagerly 2022-12-03 10:54:38 -05:00
Greg Johnston
1fa023ee08 Merge branch 'leptos_dom_v2' of https://github.com/jquesada2016/leptos into leptos_dom_v2 2022-12-03 10:35:58 -05:00
Greg Johnston
cc1c264548 ._child() helper for macro (merges child and dyn_child) 2022-12-03 10:34:27 -05:00
Jose Quesada
11960efb1b impl Deref<Target = web_sys::HtmlElement> for HtmlElement<El>` 2022-12-03 08:45:29 -06:00
Jose Quesada
16706233c7 fixed Each move requiring backshifting all items 2022-12-02 21:17:27 -06:00
Ben Wishovich
7b376b6d3a Draft Builder Pattern for Render Options to add Leptos Autorender Code 2022-12-02 16:33:59 -08:00
Ben Wishovich
8fbb4abc76 Switch integrations to pass in a full path and name v the name to enable different pkg structures 2022-12-02 12:01:51 -08:00
Greg Johnston
d0ff64daaa Merge pull request #149 from gbj/a-tag-class-helper
Allow styling `<A/>` tags with `class` property
2022-12-02 14:09:10 -05:00
Greg Johnston
bb97234817 Merge pull request #148 from gbj/explicit-stable-not-required
Automatically enable the `stable` feature if you're on `stable` Rust
2022-12-02 14:08:22 -05:00
Greg Johnston
19698d86b6 Allow styling <A/> component with class 2022-12-02 13:20:07 -05:00
Greg Johnston
21ef96806f Rename ToHref to something a little more generic 2022-12-02 13:04:37 -05:00
Greg Johnston
70e18d2aeb Automatically enable the stable feature if you're on stable Rust 2022-12-02 12:56:05 -05:00
Greg Johnston
5152703f0c Clear warnings 2022-12-02 12:39:32 -05:00
Greg Johnston
3d54055573 Add <Meta/> component to leptos_meta 2022-12-02 12:36:51 -05:00
Jose Quesada
c49ed49580 refactored a bit and left the premise for fixing Move in Each 2022-12-01 23:14:30 -06:00
Greg Johnston
a5b99a3e40 Merge branches 'main' and 'main' of https://github.com/gbj/leptos 2022-12-01 21:42:02 -05:00
Greg Johnston
101e65b724 Does adding skip_feature_sets here help with CI problem? 2022-12-01 21:41:58 -05:00
Greg Johnston
a3f91604b9 Merge pull request #141 from benwis/axum-0.6
Update Axum examples to latest 0.6 release and streamline them a bit
2022-12-01 17:23:20 -05:00
Greg Johnston
a0e0194475 FxHashSet uses a faster hashing algorithm than the default SipHash 2022-12-01 17:22:35 -05:00
Greg Johnston
d266943a8f id isn't necessary in the browser version, right? 2022-12-01 17:22:05 -05:00
Ben Wishovich
f457d8f319 Fix doc test 2022-12-01 12:56:27 -08:00
Jose Quesada
86acd8a461 now reusing text nodes 2022-12-01 14:31:47 -06:00
Greg Johnston
58abe55d7b Merge branch 'main' into axum-0.6 2022-12-01 13:10:06 -05:00
Greg Johnston
634ac17095 Merge pull request #144 from Indrazar/main
update functions for Windows file directories
2022-12-01 12:43:19 -05:00
Jose Quesada
786b7abcb7 fixed Each opts to handle more edge casses 2022-12-01 07:58:28 -06:00
Ben Wishovich
79faad4aac Missed another couple imports 2022-11-30 22:41:31 -08:00
IcosaHedron
cedc68c341 remove debug string from axum integration 2022-11-30 23:20:14 -05:00
indrazar
8ec772a129 update functions for Windows file directories
- leptos_macro/src/server.rs server_macro_impl
 - integrations/axum/src/lib.rs handle_server_fns
2022-11-30 23:01:59 -05:00
Jose Quesada
05adbda4ca fixed panic when trying to get parent node 2022-11-30 20:31:09 -06:00
Jose Quesada
6db59d526f fixed panic when dropping components 2022-11-30 20:12:13 -06:00
Greg Johnston
8d671866a3 Merge pull request #142 from FDiskas/patch-1
Update example lib.rs
2022-11-30 20:47:24 -05:00
Ben Wishovich
2edc5b3b8b Remove extra print 2022-11-30 17:31:14 -08:00
Vytenis
be96a230ee Update lib.rs 2022-12-01 01:47:54 +02:00
Ben Wishovich
0f8930b6f2 Update Axum examples to latest 0.6 release and streamline things 2022-11-30 15:02:22 -08:00
Greg Johnston
2b5c4abac5 Merge pull request #140 from gbj/transition-component
Transition component
2022-11-30 16:20:02 -05:00
Jose Quesada
0149ce1be1 removed need for 2 marker nodes 2022-11-30 13:29:51 -06:00
Greg Johnston
db8c393f49 Update examples 2022-11-30 11:36:54 -05:00
Greg Johnston
f18a7b35f2 Use SignalSetter in <Transition/> API 2022-11-30 11:36:50 -05:00
Greg Johnston
a2c5855362 <Transition/> component 2022-11-30 11:27:07 -05:00
Greg Johnston
644d097cb6 Fix SignalSetter tests 2022-11-30 11:22:05 -05:00
Jose Quesada
b058e68e4e addressed errors and clippy lints 2022-11-30 09:01:16 -06:00
Greg Johnston
9c0be9e317 Finishing implementing SignalSetter wrapper. 2022-11-30 07:46:04 -05:00
Greg Johnston
0ef0417b5a Separate SSR + browser implementations, with eager creation in browser (+ string interning) 2022-11-29 22:15:27 -05:00
Jose Quesada
649378ffbe now using Range only for potentially large groups of nodes 2022-11-29 20:08:54 -06:00
Greg Johnston
5faa2efa2d Merge pull request #137 from benwis/example_readmes
Add READMEs to all examples and fix typo in todo-app-axum
2022-11-29 20:00:36 -05:00
Greg Johnston
c5a1e9a447 Copy edited and added Trunk install instructions 2022-11-29 20:00:09 -05:00
Jose Quesada
060f8d7a6a usine clone_node on cached nodes 2022-11-29 17:00:42 -06:00
Jose Quesada
b8c125cd14 initial impl of eager builder 2022-11-29 16:50:52 -06:00
Jose Quesada
33afcf6b17 impl eager setting of attr 2022-11-29 15:49:32 -06:00
Ben Wishovich
e88e131ec3 Add READMEs to all examples and fix typo in todo-app-axum 2022-11-29 13:14:59 -08:00
Greg Johnston
80df7a0dac Merge pull request #135 from ghassanachi/patch-1
Update `counters` example link in docs
2022-11-29 14:48:40 -05:00
Jose Quesada
bbb188d2f6 added some more small opts, including using only a single Range obj 2022-11-29 13:44:03 -06:00
Jose Quesada
d8f8673ad3 tuned append opt to include the limit 2022-11-29 13:11:00 -06:00
Ghassan Gedeon Achi
493f05fda1 Update counters example link in docs 2022-11-29 11:51:27 -07:00
Jose Quesada
a73c71842a added Each append opt 2022-11-29 12:49:46 -06:00
Jose Quesada
d59ce5aebf fixed replace all items opt 2022-11-29 12:01:19 -06:00
Jose Quesada
5b14aa98e9 Comment markers are now being created by cloning a reference 2022-11-29 11:15:29 -06:00
Greg Johnston
4578622b6f Merge pull request #134 from gbj/fix-router-hydration-panic
Fix out-of-order hydration issue
2022-11-29 08:56:03 -05:00
Jose Quesada
f78400a955 fixed merge conflict 2022-11-29 07:44:47 -06:00
Jose Quesada
488856fdcc removed broken debug assertions 2022-11-29 07:37:33 -06:00
Greg Johnston
c7dd6200e8 Fix GTK example 2022-11-29 07:07:10 -05:00
Greg Johnston
6e20f31df1 Fix out-of-order hydration issue by removing old code that was handling this in an incorrect way 2022-11-29 07:06:25 -05:00
Greg Johnston
5f58db40f0 Merge pull request #131 from gbj/fix-3x-server-resource-fetching
Fix issue in which server-side resource are called 3x
2022-11-29 06:14:22 -05:00
Greg Johnston
321e11e97a Fix issue in which server-side resource are called 3x 2022-11-28 22:28:02 -05:00
Greg Johnston
42659e20cd Fast path for clearing 2022-11-28 21:51:23 -05:00
Greg Johnston
54b7b780c8 (Some of?) these debug assertions seem to break the release build 2022-11-28 21:37:47 -05:00
Greg Johnston
c472a1c5ef Fix misnamed optional-import feature exclusion that was causing CI to break 2022-11-28 20:50:04 -05:00
Jose Quesada
a638c3d39a removed superfluous console::log 2022-11-28 19:13:46 -06:00
Jose Quesada
ebb50cff6c fixed building on non-browser targets 2022-11-28 19:04:00 -06:00
Jose Quesada
9424c293d7 fixed ops conflicting with each other 2022-11-28 18:49:06 -06:00
Jose Quesada
0b72c5550b fixed Each clear opt 2022-11-28 17:26:48 -06:00
Jose Quesada
698527ddf6 fixed building in release 2022-11-28 15:02:09 -06:00
Jose Quesada
af067361a9 checking to make sure children is not empty before applying replace opt 2022-11-28 14:19:31 -06:00
Jose Quesada
04aa1585fa optimized the case of replacing all items in an Each 2022-11-28 14:04:14 -06:00
Jose Quesada
9e84a2c273 Each now optimized for clearing 2022-11-28 13:30:37 -06:00
Jose Quesada
9050572c68 EachItem is now removing it's direct children 2022-11-28 13:21:13 -06:00
Jose Quesada
40c6081256 DynChild is now responsible for removing it's direct children rather than relying on WebSysNode 2022-11-28 13:12:22 -06:00
Greg Johnston
1180eeeadb Merge pull request #127 from akesson/cargo-path-fix
Fix path deps' going one level too high
2022-11-28 12:17:32 -05:00
Jose Quesada
484e6796c0 Component now creating a child scope` 2022-11-28 08:59:35 -06:00
Greg Johnston
fdef43c2fc Small performance optimizations: wasm-bindgen string interning and cached document() (+ a function to mount to any parent) 2022-11-28 08:45:09 -05:00
Greg Johnston
2348bbc5cc Merge branch 'main' of https://github.com/gbj/leptos 2022-11-28 08:42:23 -05:00
Greg Johnston
ee41ea8b1d Update axum integration 2022-11-28 08:42:19 -05:00
Greg Johnston
a0ea3cfd7c Merge pull request #126 from benwis/axum-server-functions
Mostly working version of axum with server functions
2022-11-28 08:41:37 -05:00
Greg Johnston
edb0f8c848 Fix import for CSR/no-features verson 2022-11-28 07:43:31 -05:00
Greg Johnston
2b71c07fa9 Guard against fragments that don't actually exist 2022-11-28 07:39:30 -05:00
Greg Johnston
a109e3d51c Remove my unnecessary nested closure 2022-11-28 07:39:17 -05:00
Greg Johnston
40a842ff1d Correct name of the root component we're rendering 2022-11-28 07:39:04 -05:00
hakesson
17baec46b7 Fix path deps' going one level too high 2022-11-28 06:03:56 +01:00
Ben Wishovich
fe5c9c6f0d Fix accept heading behavior in Axum to match Actix 2022-11-27 18:25:43 -08:00
Ben Wishovich
6c22c47bbf Cleanup, it now works except for when the server FN response is () or empty 2022-11-27 17:17:34 -08:00
Ben Wishovich
2d88a113c4 Typoed 2022-11-27 17:04:34 -08:00
Ben Wishovich
b0dd759bcf Remove commented code in main 2022-11-27 17:01:42 -08:00
Ben Wishovich
507191e1a4 Mostly working version of axum with server functions 2022-11-27 16:55:38 -08:00
Greg Johnston
90854e38e6 Add event system 2022-11-27 19:42:37 -05:00
Jose Quesada
8fac1c5b3a greatly improved tracing visibility 2022-11-27 17:17:24 -06:00
Jose Quesada
6439964ef6 made children field of Component pub and added Component example to examples/test-bench 2022-11-27 11:57:35 -06:00
Jose Quesada
5b612d8084 fixed Component not mounting children on into_node calls 2022-11-27 11:46:36 -06:00
Jose Quesada
b2d9bc4aa8 removed duplicate value, as duplicate keys are invalid 2022-11-27 11:34:35 -06:00
Jose Quesada
f615dae87c applied new rustfmt config and added HtmlElement::dyn_attr 2022-11-27 11:32:18 -06:00
Jose Quesada
79058e1535 impl IntoNode for [Node; N] and `[HtmlElement<El>; N] 2022-11-27 09:49:57 -06:00
Jose Quesada
a51c12d152 added HtmlElement::attr_bool helper method 2022-11-27 09:45:38 -06:00
Jose Quesada
8999a24ec3 can now set id and attrs 2022-11-27 09:34:19 -06:00
Greg Johnston
36de06f183 0.0.19 2022-11-27 09:13:21 -05:00
Jose Quesada
da1916e35a renamed Each to EachKey 2022-11-27 07:29:17 -06:00
Jose Quesada
b1987648cf addressed most clippy lints 2022-11-27 07:20:33 -06:00
Jose Quesada
001323c058 fixed compilation on non-browser targets 2022-11-27 07:09:07 -06:00
Jose Quesada
55633560e7 Each is now fully working 2022-11-26 20:59:54 -06:00
Greg Johnston
b54c0f14e8 Remove erroneous Clone bound on calling WriteSignal as a function 2022-11-26 21:24:55 -05:00
Greg Johnston
41c03852e1 Create SignalSetter wrapper for writable signals corresponding to Signal wrapper for readable signals 2022-11-26 21:15:19 -05:00
Jose Quesada
be60713b13 updated prepare_for_move to use Range 2022-11-26 19:36:25 -06:00
Jose Quesada
000a4bf62d initial (broken move) impl of Each 2022-11-26 18:49:51 -06:00
Greg Johnston
c3fb9396e1 Add RwSignal::split() 2022-11-26 17:35:46 -05:00
Greg Johnston
3a9d16ad29 Add RwSignal::write_only() 2022-11-26 17:33:13 -05:00
Greg Johnston
c0709b210d Enable wasm-bindgen string interning for certain types by default 2022-11-26 17:19:11 -05:00
Greg Johnston
569fa9b1c6 Fix CI w.r.t. server functions 2022-11-26 17:13:35 -05:00
Greg Johnston
ed24e47c1d Add examples of canceling in-flight requests (issue #32) and filter against empty IDs to avoid extra requests (issue #123) 2022-11-26 15:29:46 -05:00
Jose Quesada
68938054ca removed name and rename from DynChild 2022-11-26 09:37:56 -06:00
Jose Quesada
368b96424d refactored components to not render as many comments in prod 2022-11-26 09:33:57 -06:00
Greg Johnston
fdd07aafb7 #[server] docs 2022-11-26 09:02:36 -05:00
Greg Johnston
1a0168bf28 Clear warnings 2022-11-26 09:02:26 -05:00
Greg Johnston
de524e21b1 Clear warnings 2022-11-26 09:01:05 -05:00
Greg Johnston
dbe3daf16a Update skip lists for CI 2022-11-26 08:43:18 -05:00
Jose Quesada
c5da652ac1 renamed Fragment representation from <Frgament> to <> 2022-11-26 07:17:12 -06:00
Jose Quesada
38f71a3cc9 impl Default for all HTML tags 2022-11-26 07:16:15 -06:00
Greg Johnston
3f6eeb319a NodeRef should actually track so you can use it in effects 2022-11-26 08:01:19 -05:00
Greg Johnston
db34565959 Merge pull request #107 from benwis/msgpack-encoding
Binary encoding as an option for server functions
2022-11-25 22:44:53 -05:00
Ben Wishovich
d5cd2b814e Make cargo check happy 2022-11-25 17:05:27 -08:00
Jose Quesada
2d21146665 basic CSR is working 2022-11-25 17:39:42 -06:00
Greg Johnston
2b9ac037e3 Merge pull request #120 from gbj/node-ref
Change `_ref` attribute to use `NodeRef` type
2022-11-25 17:45:11 -05:00
Greg Johnston
66ecc2ac25 Fix NodeRef doctest 2022-11-25 16:53:48 -05:00
Greg Johnston
4093f4c2d8 Fix todomvc 2022-11-25 16:28:21 -05:00
Greg Johnston
a46e92bed8 Clean up Fn implementation issue 2022-11-25 15:48:40 -05:00
Greg Johnston
611a1aeb28 Use relative paths in book for CI 2022-11-25 15:48:32 -05:00
Greg Johnston
994debea3f Change _ref attribute to use NodeRef type 2022-11-25 15:38:46 -05:00
Jose Quesada
24b1fc01ca added impl IntoNode for most types IntoChild supported 2022-11-25 14:37:47 -06:00
Greg Johnston
5399f54255 Merge pull request #117 from gbj/router-rerenders
Fix issue #115
2022-11-25 14:53:23 -05:00
Greg Johnston
22668f7999 Merge branch 'msgpack-encoding' of https://github.com/benwis/leptos into pr/107 2022-11-25 14:52:19 -05:00
Greg Johnston
f7b1e732c7 Update integrations 2022-11-25 14:52:14 -05:00
Greg Johnston
93f68e022f Merge branch 'main' into msgpack-encoding 2022-11-25 14:35:52 -05:00
Greg Johnston
2b4dc76d95 Clear warnings in examples 2022-11-25 14:34:14 -05:00
Greg Johnston
55f70367b5 Clear warnings in library 2022-11-25 14:32:25 -05:00
Greg Johnston
a01b0cbbc6 Clear warnings from examples 2022-11-25 14:31:03 -05:00
Greg Johnston
6d329f33eb Remove logging 2022-11-25 14:29:26 -05:00
Greg Johnston
5a863ec411 Actix implementation 2022-11-25 14:28:03 -05:00
Jose Quesada
fbfdb9fd15 now collecting Scope only on `IntoNode::into_node 2022-11-25 13:10:51 -06:00
Greg Johnston
4800600e4f original_path() for <Outlet/> logic 2022-11-25 13:48:39 -05:00
Greg Johnston
a051b1e08c Proper <Outlet/> logic so we only rerender if it's actually a different parameter 2022-11-25 13:46:55 -05:00
Greg Johnston
4a426be6fb Logging to track rerenders 2022-11-25 13:44:58 -05:00
Jose Quesada
54074409ab only std::prelude clashing structs should have a trailing _ 2022-11-25 07:39:15 -06:00
Greg Johnston
d9ab70de0d Untrack <Outlet/> child to avoid rerenders 2022-11-25 07:57:09 -05:00
Jose Quesada
e738c5c41f forgot to redirect docs to the builder fn 2022-11-24 21:37:46 -06:00
Jose Quesada
d3ec86ab18 added all HTML elements 2022-11-24 21:35:40 -06:00
Greg Johnston
aaac1d37ac Untrack to avoid double-rendering <Outlet/> 2022-11-24 22:22:27 -05:00
Jose Quesada
ce5b8f95e7 forgot to insert opening and closing component marker nodes into the document fragment 2022-11-24 16:57:44 -06:00
Jose Quesada
6bb20aed15 initial API design 2022-11-24 14:45:31 -06:00
Jose Quesada
9b3c9eb90b clean slate 2022-11-24 09:16:57 -06:00
Greg Johnston
498b5345d5 Fix Outlet 2022-11-24 08:51:53 -05:00
Greg Johnston
02a7af2c1e Reduce exponential rerenders to max of 2 2022-11-24 08:40:47 -05:00
Greg Johnston
e465867b30 Fixes issue #110 and improves #[component] docs overall 2022-11-24 07:48:57 -05:00
Greg Johnston
835c465c34 T in For component does *not* need to be Eq 2022-11-24 06:41:15 -05:00
Greg Johnston
45e2c09e53 Merge pull request #114 from safx/typed-event-handlers
Add typed event handlers
2022-11-23 19:04:32 -05:00
Greg Johnston
19d7b8434b Merge branch 'main' into typed-event-handlers 2022-11-23 19:03:52 -05:00
Ben Wishovich
3ac92dc0fe Switched out string for Payload enum in register() function and REGISTERED_SERVER_FUNCTIONS. Not sure if this is the way to go 2022-11-23 15:58:15 -08:00
Greg Johnston
6949750668 Fixing tests and examples 2022-11-23 18:29:20 -05:00
Ben Wishovich
440719071a Switch MessagePack for CBOR, as it's more standardized 2022-11-23 14:23:49 -08:00
Greg Johnston
588ebf51a5 Fix event type in router 2022-11-23 16:54:45 -05:00
Greg Johnston
3a65ad9a51 Fix type inference on server 2022-11-23 16:54:41 -05:00
Greg Johnston
7a10ffd150 A couple small DX improvements re: we, and making sure it builds /tests properly 2022-11-23 15:12:21 -05:00
Greg Johnston
a23d80fe27 Merge pull request #113 from gbj/dx-improvements
Doc and error message improvements
2022-11-23 11:10:20 -05:00
Greg Johnston
6966ef4b39 Fix renderer panic issue on release builds 2022-11-23 11:03:16 -05:00
Greg Johnston
e0c8b827c4 Fix leptos_dom tests 2022-11-23 10:24:50 -05:00
Greg Johnston
ebef5156a5 Final fix to render_to_string tests 2022-11-23 09:59:24 -05:00
safx
f3947abdc2 Merge branch 'main' into typed-event-handlers 2022-11-23 22:51:31 +09:00
Safx
701a12ab46 Add typed event handlers 2022-11-23 22:50:26 +09:00
Greg Johnston
fe830e524c Add docs for component macro (fixes issues #106 and #111) 2022-11-23 07:58:01 -05:00
Greg Johnston
6ddef3018f Better errors on renderer bugs (fixes issue #112) 2022-11-23 07:37:47 -05:00
Greg Johnston
0cbab3ef87 Don't run render_to_string test if csr or hydrate is enabled 2022-11-23 07:21:19 -05:00
Greg Johnston
4fda94144b Add run_child_scope helper 2022-11-23 07:08:18 -05:00
Greg Johnston
b6d902a584 Passes leptos_server tests now 2022-11-22 21:44:02 -05:00
Greg Johnston
102fb9d819 Fix render_to_string test 2022-11-22 21:18:28 -05:00
Greg Johnston
545fcce97c Set book chapters to depend on latest version explicitly 2022-11-22 20:52:46 -05:00
Greg Johnston
33424683d0 Merge pull request #108 from jasonrhansen/fix-counters-example
Assign correct ids in `add_many_counters`
2022-11-22 20:48:50 -05:00
Greg Johnston
19c3186d3f Add a simple render_to_string() helper for synchronous HTML rendering 2022-11-22 19:51:05 -05:00
Greg Johnston
3482f456f8 Add metadata field for integrations 2022-11-22 19:45:38 -05:00
Jason Rodney Hansen
d8a97a81ff Assign correct ids in add_many_counters
The counters and counters-stable examples didn't assign the correct ids when
clicking the "Add 1000 Counters" button if there were already counters added,
which meant clicking the "x" to remove them would remove the wrong counter.
2022-11-22 17:00:04 -07:00
Ben Wishovich
931e60347d It mostly works now. Remove lifetime, edit macro to take encoding option, and flail around a bit 2022-11-22 15:12:45 -08:00
Ben Wishovich
2a547936d4 Almost there maybe? 2022-11-22 10:41:15 -08:00
Greg Johnston
2ce7e71748 0.0.18 2022-11-22 07:37:34 -05:00
Greg Johnston
4f205b5368 0.0.18 2022-11-22 07:32:12 -05:00
Greg Johnston
8e624d4942 Update book 2022-11-22 07:32:05 -05:00
Greg Johnston
cee32a3f8f Merge pull request #105 from gbj/thread-local-runtimes
Thread local runtimes
2022-11-22 07:29:21 -05:00
Greg Johnston
e827ee93e2 leptos_server doctests 2022-11-22 06:42:00 -05:00
Ben Wishovich
6b77b51fa0 Get a bit closer with the macro 2022-11-21 22:38:53 -08:00
Ben Wishovich
6564b95342 WIP commit for MessagePack Encoding 2022-11-21 22:07:56 -08:00
Greg Johnston
2651bf5fef Fix meta and router tests 2022-11-21 22:45:56 -05:00
Greg Johnston
10d19f7fb3 leptos_macro tests 2022-11-21 22:27:25 -05:00
Greg Johnston
00de5d0d88 Fix Suspense doctest 2022-11-21 22:14:17 -05:00
Greg Johnston
0f0e3da407 Fix map_keyed test 2022-11-21 22:03:13 -05:00
Greg Johnston
4a741d772b Fix import in test 2022-11-21 21:50:29 -05:00
Greg Johnston
6c521226e3 Update other packages to handle new thread-local reactives 2022-11-21 21:46:07 -05:00
Greg Johnston
739e7db49d Support for multiple, independent Runtimes on a single thread without leaking 2022-11-21 21:11:03 -05:00
Greg Johnston
7c79cb1b1f Merge pull request #102 from gbj/meta-docs
Fixes issue #98
2022-11-21 16:50:39 -05:00
Greg Johnston
4f522d135b Fx doctests 2022-11-21 16:50:04 -05:00
Greg Johnston
60ecd740f5 Fix root doctest 2022-11-21 16:08:53 -05:00
Greg Johnston
b707eada86 Fix root-level doctest 2022-11-21 10:50:43 -05:00
Greg Johnston
71594daa93 Fix root doctest 2022-11-21 10:50:12 -05:00
Greg Johnston
89f837d3b6 Fixes #98, cleans up leptos_meta, and improves interface by removing manual .into() calls 2022-11-21 10:47:54 -05:00
Greg Johnston
014b5f9453 Update note in router docs 2022-11-21 09:54:10 -05:00
Greg Johnston
55896d97b8 Clear warning 2022-11-21 09:40:48 -05:00
Greg Johnston
5e532b60b0 prevent_default until after navigation so a failed navigation will fall back to browser navigation 2022-11-21 09:40:42 -05:00
Greg Johnston
a3181dea64 Clear some form-related warnings 2022-11-21 09:35:09 -05:00
Greg Johnston
1f1218bbb7 Fix broken links and other issues in docs 2022-11-21 09:25:09 -05:00
Greg Johnston
9322cc991b Provide whole Request<Body> to server functions in Axum 2022-11-21 07:37:58 -05:00
Greg Johnston
d0c6319a72 Resolves issue #97 2022-11-21 07:30:13 -05:00
Greg Johnston
9f1b27ad26 Merge pull request #101 from gbj/server-integrations
Server integrations for Axum and Actix
2022-11-21 07:07:03 -05:00
Greg Johnston
986cd2979a Remove unused Request/Response stuff in router 2022-11-20 22:13:31 -05:00
Greg Johnston
8b3a8489b6 handle_server_fns for Axum 2022-11-20 22:13:17 -05:00
Greg Johnston
525a31bf3d Working render_app_to_stream for Axum 2022-11-20 18:28:47 -05:00
Greg Johnston
f773f52abc Initial work on Axum integration 2022-11-20 17:41:04 -05:00
Greg Johnston
257c07325e Version number to 0.0.1 2022-11-20 16:08:02 -05:00
Greg Johnston
01a1226c53 TODO handling the runtime leak in general 2022-11-20 16:06:16 -05:00
Greg Johnston
5208616178 Consolidate functions 2022-11-20 16:05:07 -05:00
Greg Johnston
4e8c1758c3 render_app_to_stream helper in leptos_actix 2022-11-20 16:03:08 -05:00
Greg Johnston
cbcd7e506f Merge pull request #95 from gbj/server-context-in-server-fns
Allow accessing `Scope` from server functions
2022-11-20 15:46:52 -05:00
Greg Johnston
eff42a196f actix-web integration with builtin server function handler route 2022-11-20 15:25:45 -05:00
Greg Johnston
20634e38a1 Refer to full type, in case it hasn't been imported 2022-11-20 15:04:05 -05:00
Greg Johnston
4f3d7dc492 Add server context to counter-isomorphic example 2022-11-20 14:18:27 -05:00
Greg Johnston
6ddc720227 Allow accessing Scope from server functions, which can be used to inject server-only dependencies like HttpRequest 2022-11-19 14:44:35 -05:00
Greg Johnston
8077ae9ead Doctests: opt out of running futures on csr and hydrate outside the browser 2022-11-19 07:39:09 -05:00
Greg Johnston
75de8a95b6 Make todo-app-sqlite work in fully-WASMless mode with <Suspense/> and streaming 2022-11-19 07:36:16 -05:00
Greg Johnston
63d06211b9 Fix which Span this is using 2022-11-18 16:46:54 -05:00
Greg Johnston
ba199e1acb Fix doctests out of date with new API 2022-11-18 16:46:41 -05:00
Greg Johnston
9f4b3c9f26 Clear warnings 2022-11-18 16:46:25 -05:00
Greg Johnston
d654a13541 Clear some macro warnings 2022-11-18 16:39:17 -05:00
Greg Johnston
63ae4e7dda Fix dependency version numbers 2022-11-18 15:47:45 -05:00
Greg Johnston
ad880efc0d leptos 0.0.17 and leptos_router 0.0.3 2022-11-18 15:45:04 -05:00
Greg Johnston
5ff806d35a Merge pull request #92 from gbj/action-api
`Action` and `MultiAction` API changes
2022-11-18 15:21:07 -05:00
Greg Johnston
165ec069ba Deletion feature 2022-11-18 15:20:33 -05:00
Greg Johnston
be7bce03dc Optimistic UI 2022-11-18 14:58:10 -05:00
Greg Johnston
1b1182114d Fix up example since there's no CSR option 2022-11-18 13:53:16 -05:00
Greg Johnston
412693c2c3 MultiAction, create_multi_action, create_server_multi_action, and MultiActionForm 2022-11-18 13:25:46 -05:00
Greg Johnston
5c36f0963c Initial version of todo app with sqlite 2022-11-18 13:25:12 -05:00
Greg Johnston
491f124669 Merge pull request #89 from jquesada2016/main
Add ability to get/set signals untracked
2022-11-18 12:13:07 -05:00
Greg Johnston
43524c0135 Clean up docs on counter-isomorphic 2022-11-18 11:48:08 -05:00
Greg Johnston
5562e2d6ee Tests 2022-11-18 11:30:26 -05:00
Greg Johnston
bbf2d69b55 Merge pull request #90 from gbj/self-triggering-effect
Allow triggering an effect to re-run from within the effect
2022-11-18 11:28:08 -05:00
Jose Quesada
00b6b39ee0 impl UntrackedGettableSignal for MaybeSignal 2022-11-18 10:08:28 -06:00
Jose Quesada
3d88227bac impl UntrackedGettableSignal for Signal 2022-11-18 10:01:35 -06:00
Greg Johnston
d530b28348 Give direct access to input and value fields on actions 2022-11-18 10:56:00 -05:00
Greg Johnston
97a7240e26 Correct docs on create_scope and child_scope 2022-11-18 10:41:19 -05:00
Greg Johnston
2ad49a0a7e Restore view-tests 2022-11-18 10:28:23 -05:00
Greg Johnston
58e0bead02 Fix JS path in hackernews example 2022-11-18 10:24:36 -05:00
Jose Quesada
fe41b6c840 renamed UntrackedSettableSignal::set to set_untracked 2022-11-18 08:27:14 -06:00
Greg Johnston
8e2930141a ... oops. This is why we have tests. 2022-11-17 21:30:35 -05:00
Jose Quesada
36777c2055 Merge branch 'main' of https://github.com/jquesada2016/leptos 2022-11-17 19:30:33 -06:00
Greg Johnston
7ad8a6bef2 Clear up some r-a issues (and allow for stable in future) 2022-11-17 20:30:32 -05:00
Greg Johnston
e26393a42c Fix router issues 2022-11-17 20:30:18 -05:00
Jose Quesada
6e78e85590 impl UntrackedSettableSignal for WriteSignal, RwSignal 2022-11-17 19:30:05 -06:00
Greg Johnston
46b1a96cc7 Allow triggering an effect to re-run from within the effect (so that e.g., you can get() and set() the same signal within the effect — see issue #83) 2022-11-17 20:16:57 -05:00
jquesada2016
d35fdf71ed Merge branch 'gbj:main' into main 2022-11-17 19:06:33 -06:00
Greg Johnston
0473093d0a Merge pull request #88 from gbj/signal-wrappers
Provide `Signal<T>` and `MaybeSignal<T>` wrapper types.
2022-11-17 19:50:12 -05:00
Jose Quesada
4a187e83f7 impl UntrackedGettableSignal for ReadSignal, RwSignal, and Memo 2022-11-17 18:46:59 -06:00
Greg Johnston
d6c6ab7939 Create list of common bugs (includes #82 and #83) 2022-11-17 18:20:54 -05:00
Greg Johnston
5b64af1fed Fix doctests 2022-11-17 17:55:57 -05:00
Greg Johnston
72f20f7413 Remove to clarify docs 2022-11-17 17:45:58 -05:00
Greg Johnston
f4e5ef41b2 Relax constraint on with function 2022-11-17 17:45:52 -05:00
Greg Johnston
f709b46d29 Add generic wrappers for signal types 2022-11-17 17:45:43 -05:00
Greg Johnston
f87ac34656 Merge pull request #86 from benwis/axum-example
Working Axum Example!
2022-11-17 09:08:26 -05:00
Ben Wishovich
13a1d2efaa Merge branch 'gbj:main' into axum-example 2022-11-16 18:34:01 -08:00
Ben Wishovich
cae3bb8bbd Fix CSS imports, is a bit clunky though 2022-11-16 17:26:45 -08:00
Greg Johnston
77504de8f1 Correctly set value and input when using <ActionForm/> so we can do real optimistic UI (see issue #51) 2022-11-16 20:16:21 -05:00
Greg Johnston
c17c6549cf Resolve ambiguous main import error 2022-11-16 20:15:29 -05:00
Ben Wishovich
971f75b6c5 It mostly works, except for the CSS 2022-11-16 16:09:51 -08:00
Ben Wishovich
fc6a3c0eb2 Getting closer 2022-11-16 13:36:35 -08:00
Ben Wishovich
cca63e6724 Closer to the goal! 2022-11-16 13:05:06 -08:00
Ben Wishovich
becd107290 Commited almost working example 2022-11-16 08:13:49 -08:00
Ben Wishovich
36f86afa02 Merge remote-tracking branch 'origin/main' into axum-example 2022-11-16 07:41:52 -08:00
Greg Johnston
96238c553e Fix router example rendering 2022-11-16 07:24:21 -05:00
Greg Johnston
3c3e87f97c Merge pull request #81 from gbj/send-streaming
Make `render_to_stream()` return a `Stream` that is `Send`
2022-11-16 07:08:54 -05:00
Greg Johnston
fd6c2d3059 Combine resources and suspenses so it's possible for suspenses to resolve first 2022-11-16 07:07:54 -05:00
Greg Johnston
2173bb8a29 Implements render_to_stream() in a way that is Send 2022-11-15 22:20:25 -05:00
Ben Wishovich
19f89633ff Some more WIP improvements for the Axum example 2022-11-15 14:55:38 -08:00
Ben Wishovich
3885816699 Add hackernews-axum example 2022-11-15 14:08:09 -08:00
Greg Johnston
21471f809f Merge pull request #78 from gbj/fix-router-example
Fix rendering issues
2022-11-15 13:27:41 -05:00
Greg Johnston
ccb5aeac6d Resolving lots of sibling order issues 2022-11-15 12:52:50 -05:00
Greg Johnston
04b20ebad4 Merge branch 'main' of https://github.com/gbj/leptos 2022-11-15 12:12:13 -05:00
Greg Johnston
e74e9a3fc9 Restore logging functions 2022-11-15 12:11:44 -05:00
Greg Johnston
4ba9844852 Rendering work 2022-11-15 12:11:35 -05:00
Greg Johnston
7498282936 Merge pull request #76 from benwis/example-improvements
Updated hacker_news and counter-isomorphic to SFA format, fixed Router example, and added some READMEs
2022-11-14 22:20:34 -05:00
Greg Johnston
a94e739725 Small changes to fix CI and clean up 2022-11-14 22:19:21 -05:00
Greg Johnston
780c6d2e64 Improvements to the view macro to handle a wider variety of positions/relationships between child nodes 2022-11-14 21:33:49 -05:00
Ben Wishovich
067b52f731 Fix missing import that is needed sometime 2022-11-14 17:18:11 -08:00
Ben Wishovich
40ed424116 Add denylist for optional Cargo features 2022-11-14 16:57:08 -08:00
Ben Wishovich
9c59564e16 Update cfg to make CI happy and remove some extra imports 2022-11-14 16:08:34 -08:00
Ben Wishovich
11f375fdaa Fix another booboo in js imports 2022-11-14 15:02:58 -08:00
Ben Wishovich
bf301c2266 Fix issue with old import 2022-11-14 14:57:47 -08:00
Ben Wishovich
107f7c05c6 Fix README typo 2022-11-14 14:56:12 -08:00
Ben Wishovich
e9c1846470 counter-isomorphic mostly works now 2022-11-14 14:52:05 -08:00
Greg Johnston
796764493b Fix <Suspense/> part of example 2022-11-14 17:31:57 -05:00
Greg Johnston
b0f64aacba leptos_router should default to csr like leptos and leptos_macro 2022-11-14 17:31:45 -05:00
Greg Johnston
7cfd6fa42b Clear warnings in Suspense 2022-11-14 17:12:26 -05:00
Greg Johnston
745317a79b Additions to reactivity chapter 2022-11-14 16:58:35 -05:00
Greg Johnston
777f25e311 Add ability to use mermaid diagrams for reactive graphs 2022-11-14 16:58:22 -05:00
Ben Wishovich
b9e0255016 Commit working version of Router with render bug 2022-11-14 13:45:22 -08:00
Ben Wishovich
74b2889e8a Add provide_context to router example 2022-11-14 13:37:58 -08:00
Ben Wishovich
482c84dc73 Add README to router example 2022-11-14 13:19:11 -08:00
Ben Wishovich
8c0385d94c Add context to router example 2022-11-14 13:17:56 -08:00
Ben Wishovich
1c81337024 Merge branch 'main' into example-improvements 2022-11-14 13:17:39 -08:00
Ben Wishovich
992983efd9 Commit WIP version of isomorphic counter 2022-11-14 12:04:26 -08:00
Ben Wishovich
d8c2cab64d Fix crate name 2022-11-14 09:15:56 -08:00
Ben Wishovich
0f2715290c Updated hacker news example to new SFA format and added a README 2022-11-14 09:03:44 -08:00
Greg Johnston
22eaa92355 Use serde_urlencoded for server functions (making it easier to use normal text inputs for forms) 2022-11-14 08:18:01 -05:00
Greg Johnston
f8de0fff81 Allow prefixes for server function routes 2022-11-14 07:21:05 -05:00
Greg Johnston
d9f07111e0 Address issue #69 by adding caller filename to server fn URLs 2022-11-13 20:42:56 -05:00
Greg Johnston
d4da7e0c25 Allow returning <template> from view 2022-11-13 15:58:49 -05:00
Greg Johnston
876aa0f0f4 Fixing ch04 reactivity example (incomplete) 2022-11-13 09:25:22 -05:00
Greg Johnston
05f635f4ac Don't require specific subminor versions in dev-dependencies 2022-11-13 09:04:25 -05:00
Greg Johnston
ba3156c878 0.0.16 2022-11-13 09:02:04 -05:00
Greg Johnston
e24fb3b294 Ongoing work on book 2022-11-13 08:58:39 -05:00
Greg Johnston
c347e85de7 Fix doctest to reflect the fact that create_effect doesn't run in SSR mode 2022-11-13 07:08:42 -05:00
Greg Johnston
a298bc73dd Fix hydration example 2022-11-12 21:57:37 -05:00
Greg Johnston
2c894f6a1d Remove tests for dash prefixes now that they're removed 2022-11-12 20:40:40 -05:00
Greg Johnston
50cc2f5eac Don't run DOM functions in doctests 2022-11-12 20:16:21 -05:00
Greg Johnston
aacc2fc902 Merge pull request #75 from gbj/update-syn-rsx
Update to `syn-rsx` 0.9
2022-11-12 20:13:32 -05:00
Greg Johnston
48e934cd40 Remove references to dash-pattern in docs 2022-11-12 20:13:12 -05:00
Greg Johnston
8d67aa1ff0 Fix issues when rendering adjacent blocks/text 2022-11-12 20:03:16 -05:00
Greg Johnston
0920cc0cef Remove extraneous code from counter example 2022-11-12 19:38:20 -05:00
Greg Johnston
12fc1ca7a1 Clear warnings 2022-11-12 19:30:47 -05:00
Greg Johnston
a22dc69729 Prevent Suspense test from running in SSR (because no local Tokio thread found) 2022-11-12 15:17:30 -05:00
Greg Johnston
f5ae5f4fff Final TodoMVC fix 2022-11-12 08:39:30 -05:00
Greg Johnston
8042a7002b Add fake event listeners for SSR again 2022-11-12 07:48:59 -05:00
Greg Johnston
c7826e0bc9 Continuing work 2022-11-12 07:47:57 -05:00
Greg Johnston
19ac14cf62 Figuring out the right way to handle refs/event listeners in SSR mode is hard... 2022-11-12 07:37:07 -05:00
Greg Johnston
8f88b50d34 Merge branch 'main' of https://github.com/gbj/leptos 2022-11-12 07:34:44 -05:00
Greg Johnston
281b303c80 Initial work to upgrade to 0.9 2022-11-12 07:30:37 -05:00
Greg Johnston
8315cb2dd7 Remove excluded Gtk example 2022-11-12 06:48:38 -05:00
Greg Johnston
3fe1c6ccda Merge pull request #61 from gbj/doc-patrol
Adding missing docs
2022-11-12 06:40:14 -05:00
Greg Johnston
7c8ffa9314 Merge pull request #70 from gbj/todomvc-fix
Fix toggle_all panic
2022-11-11 22:21:53 -05:00
Greg Johnston
0b5657564d Restore but hide ssr_event_listener 2022-11-11 22:17:09 -05:00
Greg Johnston
0f89e64eda Hide ssr_event_listener 2022-11-11 22:13:26 -05:00
Greg Johnston
33bbfa6f75 Merge branch 'main' into doc-patrol 2022-11-11 22:02:39 -05:00
Greg Johnston
7832b59cdd Fix pub here 2022-11-11 21:57:51 -05:00
Greg Johnston
ebf4d1308b #![deny(missing_docs)] on main package 2022-11-11 21:49:26 -05:00
Greg Johnston
0e093d2c23 Complete leptos_dom docs 2022-11-11 21:37:46 -05:00
Greg Johnston
f093a24d1a Consistency in new SSR choices 2022-11-11 21:08:08 -05:00
Greg Johnston
07e6b361e1 Fix errors that can arise from using JsCast on Element types in SSR mode 2022-11-11 19:56:30 -05:00
Greg Johnston
183745f319 Class docs 2022-11-11 17:03:54 -05:00
Greg Johnston
9a59c371fd Docs for all DOM operation wrappers 2022-11-10 22:09:28 -05:00
Greg Johnston
75354517bf Fix failing test 2022-11-10 21:45:54 -05:00
Greg Johnston
01807ea514 Fix toggle_all panic 2022-11-10 21:43:40 -05:00
Greg Johnston
e19dd0a226 Fix tests 2022-11-10 07:45:58 -05:00
Greg Johnston
8e20ab28e0 leptos_dom docs 2022-11-10 07:40:16 -05:00
Greg Johnston
3dfcf99a4c Unused file 2022-11-10 07:31:52 -05:00
Greg Johnston
1e04442f97 Fix broken links in docs 2022-11-10 07:29:22 -05:00
Greg Johnston
7799479364 Begin leptos_dom docs 2022-11-10 07:27:08 -05:00
Greg Johnston
c23bc0ef90 Add server functions to main docs 2022-11-09 21:20:14 -05:00
Greg Johnston
e3c1291942 Merge branch 'main' of https://github.com/gbj/leptos 2022-11-09 07:47:43 -05:00
Greg Johnston
3d0a8f574e Fix misplaced ref in TodoMVC 2022-11-09 07:47:17 -05:00
Greg Johnston
3730427789 Fix misplaced ref in TodoMVC 2022-11-09 07:47:05 -05:00
Greg Johnston
f94be99246 Merge pull request #67 from dglsparsons/main
Amend docs on feature flags
2022-11-09 07:38:47 -05:00
Douglas Parsons
7b7ff492fc Amend docs on feature flags
It looked a bit confusing that there were 3 `serde` feature flags and
all of them were defaults.
2022-11-09 08:03:45 +00:00
Greg Johnston
ba158bbd0f Merge pull request #66 from gbj/fix-immediate-redirect-panic
Fix immediate redirect panic
2022-11-08 23:41:32 -05:00
Greg Johnston
7352151744 Update README to clarify "isomorphic" and "Web" 2022-11-08 22:26:58 -05:00
Greg Johnston
3ad2129a4c Remove unused import 2022-11-08 22:00:25 -05:00
Greg Johnston
4e4b513c1b Fix panic if you redirect immediately in a route component 2022-11-08 21:59:25 -05:00
Greg Johnston
21d73463b0 Merge pull request #62 from gbj/fix-mixed-block-and-element
Fix issues with mixing blocks and elements
2022-11-08 11:39:33 -05:00
Greg Johnston
d5554082f9 More accurate description of r/w segregation in README 2022-11-08 09:20:17 -05:00
Greg Johnston
8ff7b4c11b #![deny(missing_docs)] on leptos_server 2022-11-08 07:30:09 -05:00
Greg Johnston
0e313b3938 Fix tests in leptos_core 2022-11-08 07:26:08 -05:00
Greg Johnston
92f4ea5888 Fixes issue #60 2022-11-08 07:15:26 -05:00
Greg Johnston
acd20a24ac Add leptos_core docs 2022-11-07 21:49:34 -05:00
Greg Johnston
63a2199405 Oops this was an accident 2022-11-07 21:26:57 -05:00
Greg Johnston
9da3c66683 #![deny(missing_docs)] on leptos_reactive 2022-11-07 21:16:44 -05:00
Greg Johnston
6b82a37dea Merge pull request #58 from gbj/fix-component-and-element-order
Fix the out-of-order component/element rendering in #53.
2022-11-06 22:22:47 -05:00
Greg Johnston
9edd8a3c74 Merge pull request #56 from gbj/fix-non-bubbling-events
Fix `focus`, `blur`, and other non-bubbling events
2022-11-06 22:09:21 -05:00
Greg Johnston
33fdc3eae1 Fix leptos important for doctests with on: 2022-11-06 20:45:50 -05:00
Greg Johnston
10e01bf989 Remove logs I reintroduced 2022-11-06 20:43:05 -05:00
Greg Johnston
49820ccba6 This should fix the out-of-order component/element rendering in #53. 2022-11-06 20:37:09 -05:00
Greg Johnston
36be004ef2 Avoid manual delegation for all the DOM events that don't bubble by default. (This is technically too conservative, as one or two of these only don't bubble on certain elements, but it's simpler than passing in the element name and only a very small deopt in those cases.) 2022-11-06 20:00:35 -05:00
Greg Johnston
b9ca0b11a2 Fix breaking CI on leptos_server 2022-11-06 07:08:57 -05:00
Greg Johnston
296e27cd4a Add notes on types that can be accepted as attributes. 2022-11-06 06:54:20 -05:00
Greg Johnston
fd3443b129 Fix TodoMVC example 2022-11-05 23:27:36 -04:00
Greg Johnston
aa3dd356c1 Fix issues with action integration with forms 2022-11-05 22:47:33 -04:00
Greg Johnston
35ca30fbab 0.0.14 2022-11-05 22:39:06 -04:00
Greg Johnston
132f0839c6 Fix 0.0.13 leptos_core 2022-11-05 22:37:29 -04:00
Greg Johnston
e9c1799a11 0.0.13 2022-11-05 22:24:59 -04:00
Greg Johnston
4577313cca Include create_action in root docs 2022-11-05 22:24:54 -04:00
Greg Johnston
f75d49fe4c Router 0.0.2 2022-11-05 22:23:12 -04:00
Greg Johnston
6a38375c66 Complete docs 2022-11-05 22:18:01 -04:00
Greg Johnston
f9f4fb0fef Remove partial create_action docs from crate level 2022-11-05 22:14:28 -04:00
Greg Johnston
42cd3f1d69 Make sure server-only stuff appears in docs 2022-11-05 22:14:19 -04:00
Greg Johnston
ade2eda26d Add docs for leptos_server 2022-11-05 20:08:03 -04:00
Greg Johnston
680b6ecc20 Remove todomvc-ssr from workspace 2022-11-05 19:55:58 -04:00
Greg Johnston
4e9d0354c6 Use localStorage for initial state of todo list 2022-11-05 19:48:12 -04:00
Greg Johnston
cccd7068f9 Remove : I have bigger plans for this 2022-11-05 19:47:17 -04:00
Greg Johnston
8f56a52615 Simplify and add comments on TodoMVC 2022-11-05 19:14:45 -04:00
Greg Johnston
6c04e91088 Fix broken class: and prop: 2022-11-05 19:11:02 -04:00
Greg Johnston
9ef350c2d6 Merge pull request #50 from gbj/remove-loaders 2022-11-05 10:25:19 -04:00
Greg Johnston
f559d47714 Merge pull request #49 from gbj/router-docs 2022-11-05 10:24:56 -04:00
Greg Johnston
1cb278f520 Merge pull request #48 from mrjoe7/actions
Add `test` action configuration #19
2022-11-04 21:10:42 -04:00
Tomas Sedlak
5cfd44474d Add test action configuration 2022-11-05 00:14:30 +01:00
503 changed files with 42617 additions and 8957 deletions

3
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,3 @@
# These are supported funding model platforms
github: gbj

45
.github/workflows/check-examples.yml vendored Normal file
View File

@@ -0,0 +1,45 @@
name: Test
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
test:
name: Check examples ${{ matrix.os }} (using rustc ${{ matrix.rust }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
rust:
- nightly
os:
- ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt
- name: Add wasm32-unknown-unknown
run: rustup target add wasm32-unknown-unknown
- name: Setup cargo-make
uses: davidB/rust-cargo-make@v1
- name: Cargo generate-lockfile
run: cargo generate-lockfile
- uses: Swatinem/rust-cache@v2
- name: Run cargo check on all examples
run: cargo make check-examples

45
.github/workflows/check-stable.yml vendored Normal file
View File

@@ -0,0 +1,45 @@
name: Test
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
test:
name: Check examples ${{ matrix.os }} (using rustc ${{ matrix.rust }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
rust:
- stable
os:
- ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt
- name: Add wasm32-unknown-unknown
run: rustup target add wasm32-unknown-unknown
- name: Setup cargo-make
uses: davidB/rust-cargo-make@v1
- name: Cargo generate-lockfile
run: cargo generate-lockfile
- uses: Swatinem/rust-cache@v2
- name: Run cargo check on all examples
run: cargo make check-stable

45
.github/workflows/check.yml vendored Normal file
View File

@@ -0,0 +1,45 @@
name: Test
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
test:
name: Run `cargo check` ${{ matrix.os }} (using rustc ${{ matrix.rust }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
rust:
- nightly
os:
- ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt
- name: Add wasm32-unknown-unknown
run: rustup target add wasm32-unknown-unknown
- name: Setup cargo-make
uses: davidB/rust-cargo-make@v1
- name: Cargo generate-lockfile
run: cargo generate-lockfile
- uses: Swatinem/rust-cache@v2
- name: Run cargo check on all libraries
run: cargo make check

34
.github/workflows/fmt.yml vendored Normal file
View File

@@ -0,0 +1,34 @@
name: Test
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
test:
name: Run rustfmt
runs-on: ${{ matrix.os }}
strategy:
matrix:
rust:
- nightly
os:
- ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt
- name: Run Rustfmt
run: cargo fmt -- --check

45
.github/workflows/test.yml vendored Normal file
View File

@@ -0,0 +1,45 @@
name: Test
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
test:
name: Run tests ${{ matrix.os }} (using rustc ${{ matrix.rust }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
rust:
- nightly
os:
- ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt
- name: Add wasm32-unknown-unknown
run: rustup target add wasm32-unknown-unknown
- name: Setup cargo-make
uses: davidB/rust-cargo-make@v1
- name: Cargo generate-lockfile
run: cargo generate-lockfile
- uses: Swatinem/rust-cache@v2
- name: Run tests with all features
run: cargo make test

1
.gitignore vendored
View File

@@ -6,3 +6,4 @@ blob.rs
Cargo.lock
**/*.rs.bk
.DS_Store
.idea

51
CODE_OF_CONDUCT.md Normal file
View File

@@ -0,0 +1,51 @@
# Contributor Covenant Code of Conduct
_This Code of Conduct is based on the [Rust Code of Conduct](https://www.rust-lang.org/policies/code-of-conduct)
and the [Bevy Code of Conduct](https://raw.githubusercontent.com/bevyengine/bevy/main/CODE_OF_CONDUCT.md),
which are adapted from the [Node.js Policy on Trolling](http://blog.izs.me/post/30036893703/policy-on-trolling)
and the [Contributor Covenant](https://www.contributor-covenant.org)._
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
We are a community of people learning and exploring how to build better web applications
with Rust. When interacting with one another, please remember that there are no experts and there are
no stupid questions. Assume the best in other people's communication, and take a step back if
you find yourself getting defensive.
Please note the following guidelines as well:
* Please avoid using overtly sexual aliases or other nicknames that might detract from a friendly, safe and welcoming environment for all.
* Please be kind and courteous. Theres no need to be mean or rude.
* Respect that people have differences of opinion and that every design or implementation choice carries a trade-off and numerous costs. There is seldom a right answer.
* Please keep unstructured critique to a minimum. If you have solid ideas you want to experiment with, make a fork and see how it works.
* We will exclude you from interaction if you insult, demean or harass anyone. That is not welcome behavior. We interpret the term “harassment” as including the definition in the [Citizen Code of Conduct](https://github.com/stumpsyn/policies/blob/master/citizen_code_of_conduct.md); if you have any lack of clarity about what might be included in that concept, please read their definition. In particular, we dont tolerate behavior that excludes people in socially marginalized groups.
* Private harassment is also unacceptable. No matter who you are, if you feel you have been or are being harassed or made uncomfortable by a community member, please contact the maintainers immediately. Whether youre a regular contributor or a newcomer, we care about making this community a safe place for you and weve got your back.
* Do not make casual mention of slavery or indentured servitude and/or false comparisons of one's occupation or situation to slavery. Please consider using or asking about alternate terminology when referring to such metaphors in technology.
* Likewise any spamming, trolling, flaming, baiting or other attention-stealing behavior is not welcome.
## Moderation
These are the policies for upholding [our communitys standards of conduct](#our-standards). If you feel that a thread needs moderation, please contact the maintainers.
1. Remarks that violate the community standards of conduct, including hateful, hurtful, oppressive, or exclusionary remarks, are not allowed. (Cursing is allowed, but never targeting another user, and never in a hateful manner).
2. Remarks that maintainers find inappropriate, whether listed in the code of conduct or not, are also not allowed.
3. Maintainers will first respond to such remarks with a warning.
4. If the warning is unheeded, the user will be “kicked,” i.e., kicked out of the communication channel to cool off.
5. If the user comes back and continues to make trouble, they will be banned, i.e., indefinitely excluded.
6. Maintainers may choose at their discretion to un-ban the user if it was a first offense and they offer the offended party a genuine apology.
7. If a maintainer bans someone and you think it was unjustified, please take it up with that maintainer, or with a different maintainer, in private. Complaints about bans in-channel are not allowed.
8. Maintainers are held to a higher standard than other community members. If a maintainer creates an inappropriate situation, they should expect less leeway than others.
The enforcement policies in the code of conduct apply to all official venues, including Discord channels, GitHub repositories, and all other forums.

View File

@@ -3,40 +3,49 @@ members = [
# core
"leptos",
"leptos_dom",
"leptos_core",
"leptos_config",
"leptos_hot_reload",
"leptos_macro",
"leptos_reactive",
"leptos_server",
"server_fn",
"server_fn_macro",
"server_fn/server_fn_macro_default",
# integrations
"integrations/actix",
"integrations/axum",
"integrations/viz",
"integrations/utils",
# libraries
"meta",
"router",
# examples
"examples/counter",
"examples/counter-isomorphic/client",
"examples/counter-isomorphic/server",
"examples/counter-isomorphic/counter",
"examples/counters",
"examples/counters-stable",
"examples/fetch",
"examples/hackernews/hackernews-app",
"examples/hackernews/hackernews-client",
"examples/hackernews/hackernews-server",
"examples/parent-child",
"examples/router",
"examples/todomvc",
"examples/todomvc-ssr/todomvc-ssr-client",
"examples/todomvc-ssr/todomvc-ssr-server",
]
exclude = [
"benchmarks",
# not gonna lie, this is because my arm64 mac fails when linking a GTK binary
"examples/gtk",
]
exclude = ["benchmarks", "examples"]
[workspace.package]
version = "0.2.4"
[workspace.dependencies]
leptos = { path = "./leptos", default-features = false, version = "0.2.4" }
leptos_dom = { path = "./leptos_dom", default-features = false, version = "0.2.4" }
leptos_hot_reload = { path = "./leptos_hot_reload", version = "0.2.4" }
leptos_macro = { path = "./leptos_macro", default-features = false, version = "0.2.4" }
leptos_reactive = { path = "./leptos_reactive", default-features = false, version = "0.2.4" }
leptos_server = { path = "./leptos_server", default-features = false, version = "0.2.4" }
server_fn = { path = "./server_fn", default-features = false, version = "0.2.4" }
server_fn_macro = { path = "./server_fn_macro", default-features = false, version = "0.2.4" }
server_fn_macro_default = { path = "./server_fn/server_fn_macro_default", default-features = false, version = "0.2.4" }
leptos_config = { path = "./leptos_config", default-features = false, version = "0.2.4" }
leptos_router = { path = "./router", version = "0.2.4" }
leptos_meta = { path = "./meta", default-feature = false, version = "0.2.4" }
leptos_integration_utils = { path = "./integrations/utils", version = "0.2.4" }
[profile.release]
codegen-units = 1
lto = true
opt-level = 'z'
[workspace.metadata.cargo-all-features]
skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]]

View File

@@ -7,18 +7,65 @@
# make tasks run at the workspace root
default_to_workspace = false
[tasks.ci]
dependencies = ["build", "test"]
[tasks.build]
[tasks.check]
clear = true
dependencies = ["build-all"]
dependencies = [
"check-all",
"check-wasm",
"check-all-release",
"check-wasm-release",
]
[tasks.build-all]
[tasks.check-all]
command = "cargo"
args = ["+nightly", "build-all-features"]
args = ["+nightly", "check-all-features"]
install_crate = "cargo-all-features"
[tasks.check-wasm]
clear = true
dependencies = [{ name = "check-wasm", path = "leptos" }]
[tasks.check-all-release]
command = "cargo"
args = ["+nightly", "check-all-features"]
install_crate = "cargo-all-features"
[tasks.check-wasm-release]
clear = true
dependencies = [{ name = "check-wasm-release", path = "leptos" }]
[tasks.check-examples]
clear = true
dependencies = [
{ name = "check", path = "examples/counter" },
{ name = "check", path = "examples/counter_isomorphic" },
{ name = "check", path = "examples/counters" },
{ name = "check", path = "examples/error_boundary" },
{ name = "check", path = "examples/errors_axum" },
{ name = "check", path = "examples/fetch" },
{ name = "check", path = "examples/hackernews" },
{ name = "check", path = "examples/hackernews_axum" },
{ name = "check", path = "examples/login_with_token_csr_only" },
{ name = "check", path = "examples/parent_child" },
{ name = "check", path = "examples/router" },
{ name = "check", path = "examples/session_auth_axum" },
{ name = "check", path = "examples/ssr_modes" },
{ name = "check", path = "examples/ssr_modes_axum" },
{ name = "check", path = "examples/tailwind" },
{ name = "check", path = "examples/tailwind_csr_trunk" },
{ name = "check", path = "examples/todo_app_sqlite" },
{ name = "check", path = "examples/todo_app_sqlite_axum" },
{ name = "check", path = "examples/todo_app_sqlite_viz" },
{ name = "check", path = "examples/todomvc" },
]
[tasks.check-stable]
clear = true
dependencies = [
{ name = "check", path = "examples/counter_without_macros" },
{ name = "check", path = "examples/counters_stable" },
]
[tasks.test]
clear = true
dependencies = ["test-all"]

130
README.md
View File

@@ -1,6 +1,7 @@
**Please note:** This framework is in active development. I'm keeping it in a cycle of 0.0.x releases at the moment to indicate that its not even ready for its 0.1.0. Active work is being done on documentation and features, and APIs should not necessarily be considered stable. At the same time, it is more than a toy project or proof of concept, and I am actively using it for my own application development.
<img src="https://raw.githubusercontent.com/gbj/leptos/main/docs/logos/logo.svg" alt="Leptos Logo" style="width: 100%; height: auto; display: block; margin: auto;">
<picture>
<source srcset="https://raw.githubusercontent.com/leptos-rs/leptos/main/docs/logos/Leptos_logo_pref_dark_RGB.svg" media="(prefers-color-scheme: dark)">
<img src="https://raw.githubusercontent.com/leptos-rs/leptos/main/docs/logos/Leptos_logo_RGB.svg" alt="Leptos Logo">
</picture>
[![crates.io](https://img.shields.io/crates/v/leptos.svg)](https://crates.io/crates/leptos)
[![docs.rs](https://docs.rs/leptos/badge.svg)](https://docs.rs/leptos)
@@ -12,7 +13,7 @@
use leptos::*;
#[component]
pub fn SimpleCounter(cx: Scope, initial_value: i32) -> Element {
pub fn SimpleCounter(cx: Scope, initial_value: i32) -> impl IntoView {
// create a reactive signal with the initial value
let (value, set_value) = create_signal(cx, initial_value);
@@ -22,13 +23,13 @@ pub fn SimpleCounter(cx: Scope, initial_value: i32) -> Element {
let decrement = move |_| set_value.update(|value| *value -= 1);
let increment = move |_| set_value.update(|value| *value += 1);
// this JSX is compiled to an HTML template string for performance
// create user interfaces with the declarative `view!` macro
view! {
cx,
<div>
<button on:click=clear>"Clear"</button>
<button on:click=decrement>"-1"</button>
<span>"Value: " {move || value().to_string()} "!"</span>
<span>"Value: " {value} "!"</span>
<button on:click=increment>"+1"</button>
</div>
}
@@ -48,71 +49,88 @@ Leptos is a full-stack, isomorphic Rust web framework leveraging fine-grained re
## What does that mean?
- **Full-stack**: Leptos can be used to build apps that run in the browser (_client-side rendering_), on the server (_server-side rendering_), or by rendering HTML on the server and then adding interactivity in the browser (_hydration_). This includes support for _HTTP streaming_ of both data (`Resource`s) and HTML (out-of-order streaming of `<Suspense/>` components.)
- **Isomorphic**: The same application code and business logic are compiled to run on the client and server, with seamless integration. You can write your server-only logic (database requests, authentication etc.) alongside the client-side components that will consume it, and let Leptos manage the data loading without the need to manually create APIs to consume.
- **Web**: Leptos is built on the Web platform and Web standards. Whenever possible, we use Web essentials (like links and forms) and build on top of them rather than trying to replace them.
- **Isomorphic**: Leptos provides primitives to write isomorphic server functions, i.e., functions that can be called with the “same shape” on the client or server, but only run on the server. This means you can write your server-only logic (database requests, authentication etc.) alongside the client-side components that will consume it, and call server functions as if they were running in the browser.
- **Web**: Leptos is built on the Web platform and Web standards. The router is designed to use Web fundamentals (like links and forms) and build on top of them rather than trying to replace them.
- **Framework**: Leptos provides most of what you need to build a modern web app: a reactive system, templating library, and a router that works on both the server and client side.
- **Fine-grained reactivity**: The entire framework is build from reactive primitives. This allows for extremely performant code with minimal overhead: when a reactive signals value changes, it can update a single text node, toggle a single class, or remove an element from the DOM without any other code running. (_So, no virtual DOM!_)
- **Fine-grained reactivity**: The entire framework is built from reactive primitives. This allows for extremely performant code with minimal overhead: when a reactive signals value changes, it can update a single text node, toggle a single class, or remove an element from the DOM without any other code running. (_So, no virtual DOM!_)
- **Declarative**: Tell Leptos how you want the page to look, and let the framework tell the browser how to do it.
## Learn more
Here are some resources for learning more about Leptos:
- [Examples](https://github.com/gbj/leptos/tree/main/examples)
- [API Documentation](https://docs.rs/leptos/latest/leptos/) (in progress)
- [Examples](https://github.com/leptos-rs/leptos/tree/main/examples)
- [API Documentation](https://docs.rs/leptos/latest/leptos/)
- [Common Bugs](https://github.com/leptos-rs/leptos/tree/main/docs/COMMON_BUGS.md) (and how to fix them!)
- Leptos Guide (in progress)
## `nightly` Note
Most of the examples assume youre using `nightly` Rust. If youre on stable, note the following:
Most of the examples assume youre using `nightly` Rust.
1. You need to enable the `"stable"` flag in `Cargo.toml`: `leptos = { version = "0.0", features = ["stable"] }`
To set up your Rust toolchain using `nightly` (and add the ability to compile Rust to WebAssembly, if you havent already)
```
rustup toolchain install nightly
rustup default nightly
rustup target add wasm32-unknown-unknown
```
If youre on `stable`, note the following:
1. You need to enable the `"stable"` flag in `Cargo.toml`: `leptos = { version = "0.2", features = ["stable"] }`
2. `nightly` enables the function call syntax for accessing and setting signals. If youre using `stable`,
youll just call `.get()`, `.set()`, or `.update()` manually. Check out the
[`counters-stable` example](https://github.com/gbj/leptos/blob/main/examples/counters-stable/src/main.rs)
[`counters_stable` example](https://github.com/leptos-rs/leptos/blob/main/examples/counters_stable/src/main.rs)
for examples of the correct API.
## Benchmarks
## `cargo-leptos`
### Server-Side Rendering
[`cargo-leptos`](https://github.com/leptos-rs/cargo-leptos) is a build tool that's designed to make it easy to build apps that run on both the client and the server, with seamless integration. The best way to get started with a real Leptos project right now is to use `cargo-leptos` and our [starter template](https://github.com/leptos-rs/start).
Ive created a benchmark comparing Leptoss HTML rendering on the server to [Tera](https://github.com/Keats/tera), [Yew](https://github.com/yewstack/yew), and [Sycamore](https://github.com/sycamore-rs/sycamore). You can find the benchmark [here](https://github.com/gbj/leptos/tree/main/benchmarks) and run it yourself using `cargo bench`. Leptos renders HTML roughly as fast as Tera, and scales well as templates become larger. It's significantly faster than the server-side HTML rendering done by similar frameworks.
```bash
cargo install cargo-leptos
cargo leptos new --git https://github.com/leptos-rs/start
cd [your project name]
cargo leptos watch
```
<details>
<summary>Click to show results</summary>
<table>
<thead>
<tr><td><em>ns/iter</em></td><td>Tera</td><td>Leptos</td><td>Yew</td><td>Sycamore</td></tr>
</thead>
<tbody>
<tr><td>3 Counters</td><td align="right">3,454</td><td align="right">5,666</td><td align="right">34,984</td><td align="right">32,412</td></tr>
<tr><td>TodoMVC (no todos)</td><td align="right">2,396</td><td align="right">5,561</td><td align="right">38,725</td><td align="right">68,749</td></tr>
<tr><td>TodoMVC (1000 todos)</td><td align="right">3,829,447</td><td align="right">3,077,907</td><td align="right">5,125,639</td><td align="right">19,448,900</td></tr>
<tr><td><em>Average</em></td><td align="right">1.08</td><td align="right">1.65</td><td align="right">6.25</td><td align="right">9.36</td></tr>
</tbody>
</table>
</details>
### Client-Side Rendering
The gold standard for testing raw rendering performance for front-end web frameworks is the [js-framework-benchmark](https://github.com/krausest/js-framework-benchmark). The official results list Leptos as the fastest Rust/Wasm framework, slightly slower than SolidJS and significantly faster than popular JS frameworks like Svelte, Preact, and React.
<details>
<summary>Click to show results</summary>
<img width="913" alt="js-framework-benchmark results" src="https://user-images.githubusercontent.com/286622/198388168-d21e938b-5d59-4000-b373-91b48f1ec4d3.png">
</details>
Open browser on [http://localhost:3000/](http://localhost:3000/)
## FAQs
### Whats up with the name?
*Leptos* (λεπτός) is an ancient Greek word meaning “thin, light, refine, fine-grained.” To me, a classicist and not a dog owner, it evokes the lightweight reactive system that powers the framework. I've since learned the same word is at the root of the medical term “leptospirosis,” a blood infection that affects humans and animals... My bad. No dogs were harmed in the creation of this framework.
### Is it production ready?
People usually mean one of three things by this question.
1. **Are the APIs stable?** i.e., will I have to rewrite my whole app from Leptos 0.1 to 0.2 to 0.3 to 0.4, or can I write it now and benefit from new features and updates as new versions come?
With 0.1 the APIs are basically settled. Were adding new features, but were very happy with where the type system and patterns have landed. I would not expect major breaking changes to your code to adapt to, for example, a 0.2.0 release.
2. **Are there bugs?**
Yes, Im sure there are. You can see from the state of our issue tracker over time that there arent that _many_ bugs and theyre usually resolved pretty quickly. But for sure, there may be moments where you encounter something that requires a fix at the framework level, which may not be immediately resolved.
3. **Am I a consumer or a contributor?**
This may be the big one: “production ready” implies a certain orientation to a library: that you can basically use it, without any special knowledge of its internals or ability to contribute. Everyone has this at some level in their stack: for example I (@gbj) dont have the capacity or knowledge to contribute to something like `wasm-bindgen` at this point: I simply rely on it to work.
There are several people in this community using Leptos right now for internal apps at work, who have also become significant contributors. I think this is the right level of production use for now. There may be missing features that you need, and you may end up building them! But for internal apps, if youre willing to build and contribute missing pieces along the way, the framework is definitely usable right now.
### Can I use this for native GUI?
Sure! Obviously the `view` macro is for generating DOM nodes but you can use the reactive system to drive native any GUI toolkit that uses the same kind of object-oriented, event-callback-based framework as the DOM pretty easily. The principles are the same:
- Use signals, derived signals, and memos to create your reactive system
- Create GUI widgets
- Use event listeners to update signals
- Create effects to update the UI
I've put together a [very simple GTK example](https://github.com/gbj/leptos/blob/main/examples/gtk/src/main.rs) so you can see what I mean.
I've put together a [very simple GTK example](https://github.com/leptos-rs/leptos/blob/main/examples/gtk/src/main.rs) so you can see what I mean.
### How is this different from Yew/Dioxus?
@@ -120,7 +138,7 @@ On the surface level, these libraries may seem similar. Yew is, of course, the m
- **VDOM vs. fine-grained:** Yew is built on the virtual DOM (VDOM) model: state changes cause components to re-render, generating a new virtual DOM tree. Yew diffs this against the previous VDOM, and applies those patches to the actual DOM. Component functions rerun whenever state changes. Leptos takes an entirely different approach. Components run once, creating (and returning) actual DOM nodes and setting up a reactive system to update those DOM nodes.
- **Performance:** This has huge performance implications: Leptos is simply _much_ faster at both creating and updating the UI than Yew is.
- **Mental model:** Adopting fine-grained reactivity also tends to simplify the mental model. There are no surprising components re-renders because there are no re-renders. Your app can be divided into components based on what makes sense for your app, because they have no performance implications.
- **Mental model:** Adopting fine-grained reactivity also tends to simplify the mental model. There are no surprising component re-renders because there are no re-renders. Your app can be divided into components based on what makes sense for your app, because they have no performance implications.
### How is this different from Sycamore?
@@ -130,21 +148,19 @@ There are some practical differences that make a significant difference:
- **Maturity:** Sycamore is obviously a much more mature and stable library with a larger ecosystem.
- **Templating:** Leptos uses a JSX-like template format (built on [syn-rsx](https://github.com/stoically/syn-rsx)) for its `view` macro. Sycamore offers the choice of its own templating DSL or a builder syntax.
- **Template node cloning:** Leptos's `view` macro compiles to a static HTML string and a set of instructions of how to assign its reactive values. This means that at runtime, Leptos can clone a `<template>` node rather than calling `document.createElement()` to create DOM nodes. This is a _significantly_ faster way of rendering components.
- **Read-write segregation:** Leptos, like Solid, enforces read-write segregation between signal getters and setters, so you end up accessing signals with tuples like `let (count, set_count) = create_signal(cx, 0);`
- **Read-write segregation:** Leptos, like Solid, encourages read-write segregation between signal getters and setters, so you end up accessing signals with tuples like `let (count, set_count) = create_signal(cx, 0);` _(If you prefer or if it's more convenient for your API, you can use `create_rw_signal` to give a unified read/write signal.)_
- **Signals are functions:** In Leptos, you can call a signal to access it rather than calling a specific method (so, `count()` instead of `count.get()`) This creates a more consistent mental model: accessing a reactive value is always a matter of calling a function. For example:
```rust
let (count, set_count) = create_signal(cx, 0); // a signal
let double_count = move || count() * 2; // a derived signal
let memoized_count = create_memo(cx, move |_| count() * 3); // a memo
// all are accessed by calling them
assert_eq!(count(), 0);
assert_eq!(double_count(), 0);
assert_eq!(memoized_count(), 0);
```rust
let (count, set_count) = create_signal(cx, 0); // a signal
let double_count = move || count() * 2; // a derived signal
let memoized_count = create_memo(cx, move |_| count() * 3); // a memo
// all are accessed by calling them
assert_eq!(count(), 0);
assert_eq!(double_count(), 0);
assert_eq!(memoized_count(), 0);
// this function can accept any of those signals
fn do_work_on_signal(my_signal: impl Fn() -> i32) { ... }
```
// this function can accept any of those signals
fn do_work_on_signal(my_signal: impl Fn() -> i32) { ... }
```
- **Signals and scopes are `'static`:** Both Leptos and Sycamore ease the pain of moving signals in closures (in particular, event listeners) by making them `Copy`, to avoid the `{ let count = count.clone(); move |_| ... }` that's very familiar in Rust UI code. Sycamore does this by using bump allocation to tie the lifetimes of its signals to its scopes: since references are `Copy`, `&'a Signal<T>` can be moved into a closure. Leptos does this by using arena allocation and passing around indices: types like `ReadSignal<T>`, `WriteSignal<T>`, and `Memo<T>` are actually wrapper for indices into an arena. This means that both scopes and signals are both `Copy` and `'static` in Leptos, which means that they can be moved easily into closures without adding lifetime complexity.
- **Signals and scopes are `'static`:** Both Leptos and Sycamore ease the pain of moving signals in closures (in particular, event listeners) by making them `Copy`, to avoid the `{ let count = count.clone(); move |_| ... }` that's very familiar in Rust UI code. Sycamore does this by using bump allocation to tie the lifetimes of its signals to its scopes: since references are `Copy`, `&'a Signal<T>` can be moved into a closure. Leptos does this by using arena allocation and passing around indices: types like `ReadSignal<T>`, `WriteSignal<T>`, and `Memo<T>` are actually wrappers for indices into an arena. This means that both scopes and signals are both `Copy` and `'static` in Leptos, which means that they can be moved easily into closures without adding lifetime complexity.

View File

@@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021"
[dependencies]
l021 = { package = "leptos", version = "0.2.1" }
leptos = { path = "../leptos", default-features = false, features = ["ssr"] }
sycamore = { version = "0.8", features = ["ssr"] }
yew = { git = "https://github.com/yewstack/yew", features = ["ssr"] }
@@ -27,4 +28,4 @@ features = [
"Document",
"HtmlElement",
"HtmlInputElement"
]
]

View File

@@ -2,6 +2,6 @@
extern crate test;
//mod reactive;
mod ssr;
mod todomvc;
mod reactive;
//mod ssr;
//mod todomvc;

View File

@@ -1,35 +1,114 @@
use std::{cell::Cell, rc::Rc};
use test::Bencher;
use std::{cell::Cell, rc::Rc};
#[bench]
fn leptos_create_1000_signals(b: &mut Bencher) {
use leptos::{create_isomorphic_effect, create_memo, create_scope, create_signal};
fn leptos_deep_creation(b: &mut Bencher) {
use leptos::*;
let runtime = create_runtime();
b.iter(|| {
create_scope(|cx| {
let acc = Rc::new(Cell::new(0));
let sigs = (0..1000).map(|n| create_signal(cx, n)).collect::<Vec<_>>();
create_scope(runtime, |cx| {
let signal = create_rw_signal(cx, 0);
let mut memos = Vec::<Memo<usize>>::new();
for i in 0..1000usize {
let prev = memos.get(i.saturating_sub(1)).copied();
if let Some(prev) = prev {
memos.push(create_memo(cx, move |_| prev.get() + 1));
} else {
memos.push(create_memo(cx, move |_| signal.get() + 1));
}
}
})
.dispose()
});
runtime.dispose();
}
#[bench]
fn leptos_deep_update(b: &mut Bencher) {
use leptos::*;
let runtime = create_runtime();
b.iter(|| {
create_scope(runtime, |cx| {
let signal = create_rw_signal(cx, 0);
let mut memos = Vec::<Memo<usize>>::new();
for i in 0..1000usize {
let prev = memos.get(i.saturating_sub(1)).copied();
if let Some(prev) = prev {
memos.push(create_memo(cx, move |_| prev.get() + 1));
} else {
memos.push(create_memo(cx, move |_| signal.get() + 1));
}
}
signal.set(1);
assert_eq!(memos[999].get(), 1001);
})
.dispose()
});
runtime.dispose();
}
#[bench]
fn leptos_narrowing_down(b: &mut Bencher) {
use leptos::*;
let runtime = create_runtime();
b.iter(|| {
create_scope(runtime, |cx| {
let sigs =
(0..1000).map(|n| create_signal(cx, n)).collect::<Vec<_>>();
let reads = sigs.iter().map(|(r, _)| *r).collect::<Vec<_>>();
let writes = sigs.iter().map(|(_, w)| *w).collect::<Vec<_>>();
let memo = create_memo(cx, move |_| reads.iter().map(|r| r.get()).sum::<i32>());
let memo = create_memo(cx, move |_| {
reads.iter().map(|r| r.get()).sum::<i32>()
});
assert_eq!(memo(), 499500);
})
.dispose()
});
runtime.dispose();
}
#[bench]
fn leptos_create_and_update_1000_signals(b: &mut Bencher) {
use leptos::{create_isomorphic_effect, create_memo, create_scope, create_signal};
fn leptos_fanning_out(b: &mut Bencher) {
use leptos::*;
let runtime = create_runtime();
b.iter(|| {
create_scope(|cx| {
create_scope(runtime, |cx| {
let sig = create_rw_signal(cx, 0);
let memos = (0..1000)
.map(|_| create_memo(cx, move |_| sig.get()))
.collect::<Vec<_>>();
assert_eq!(memos.iter().map(|m| m.get()).sum::<i32>(), 0);
sig.set(1);
assert_eq!(memos.iter().map(|m| m.get()).sum::<i32>(), 1000);
})
.dispose()
});
runtime.dispose();
}
#[bench]
fn leptos_narrowing_update(b: &mut Bencher) {
use leptos::*;
let runtime = create_runtime();
b.iter(|| {
create_scope(runtime, |cx| {
let acc = Rc::new(Cell::new(0));
let sigs = (0..1000).map(|n| create_signal(cx, n)).collect::<Vec<_>>();
let sigs =
(0..1000).map(|n| create_signal(cx, n)).collect::<Vec<_>>();
let reads = sigs.iter().map(|(r, _)| *r).collect::<Vec<_>>();
let writes = sigs.iter().map(|(_, w)| *w).collect::<Vec<_>>();
let memo = create_memo(cx, move |_| reads.iter().map(|r| r.get()).sum::<i32>());
let memo = create_memo(cx, move |_| {
reads.iter().map(|r| r.get()).sum::<i32>()
});
assert_eq!(memo(), 499500);
create_isomorphic_effect(cx, {
let acc = Rc::clone(&acc);
@@ -48,17 +127,20 @@ fn leptos_create_and_update_1000_signals(b: &mut Bencher) {
})
.dispose()
});
runtime.dispose();
}
#[bench]
fn leptos_create_and_dispose_1000_scopes(b: &mut Bencher) {
use leptos::{create_isomorphic_effect, create_scope, create_signal};
fn leptos_scope_creation_and_disposal(b: &mut Bencher) {
use leptos::*;
let runtime = create_runtime();
b.iter(|| {
let acc = Rc::new(Cell::new(0));
let disposers = (0..1000)
.map(|_| {
create_scope({
create_scope(runtime, {
let acc = Rc::clone(&acc);
move |cx| {
let (r, w) = create_signal(cx, 0);
@@ -76,16 +158,183 @@ fn leptos_create_and_dispose_1000_scopes(b: &mut Bencher) {
disposer.dispose();
}
});
runtime.dispose();
}
#[bench]
fn sycamore_create_1000_signals(b: &mut Bencher) {
use sycamore::reactive::{create_effect, create_memo, create_scope, create_signal};
fn l021_deep_creation(b: &mut Bencher) {
use l021::*;
let runtime = create_runtime();
b.iter(|| {
create_scope(runtime, |cx| {
let signal = create_rw_signal(cx, 0);
let mut memos = Vec::<Memo<usize>>::new();
for i in 0..1000usize {
let prev = memos.get(i.saturating_sub(1)).copied();
if let Some(prev) = prev {
memos.push(create_memo(cx, move |_| prev.get() + 1));
} else {
memos.push(create_memo(cx, move |_| signal.get() + 1));
}
}
})
.dispose()
});
runtime.dispose();
}
#[bench]
fn l021_deep_update(b: &mut Bencher) {
use l021::*;
let runtime = create_runtime();
b.iter(|| {
create_scope(runtime, |cx| {
let signal = create_rw_signal(cx, 0);
let mut memos = Vec::<Memo<usize>>::new();
for i in 0..1000usize {
let prev = memos.get(i.saturating_sub(1)).copied();
if let Some(prev) = prev {
memos.push(create_memo(cx, move |_| prev.get() + 1));
} else {
memos.push(create_memo(cx, move |_| signal.get() + 1));
}
}
signal.set(1);
assert_eq!(memos[999].get(), 1001);
})
.dispose()
});
runtime.dispose();
}
#[bench]
fn l021_narrowing_down(b: &mut Bencher) {
use l021::*;
let runtime = create_runtime();
b.iter(|| {
create_scope(runtime, |cx| {
let acc = Rc::new(Cell::new(0));
let sigs =
(0..1000).map(|n| create_signal(cx, n)).collect::<Vec<_>>();
let reads = sigs.iter().map(|(r, _)| *r).collect::<Vec<_>>();
let writes = sigs.iter().map(|(_, w)| *w).collect::<Vec<_>>();
let memo = create_memo(cx, move |_| {
reads.iter().map(|r| r.get()).sum::<i32>()
});
assert_eq!(memo(), 499500);
})
.dispose()
});
runtime.dispose();
}
#[bench]
fn l021_fanning_out(b: &mut Bencher) {
use leptos::*;
let runtime = create_runtime();
b.iter(|| {
create_scope(runtime, |cx| {
let sig = create_rw_signal(cx, 0);
let memos = (0..1000)
.map(|_| create_memo(cx, move |_| sig.get()))
.collect::<Vec<_>>();
assert_eq!(memos.iter().map(|m| m.get()).sum::<i32>(), 0);
sig.set(1);
assert_eq!(memos.iter().map(|m| m.get()).sum::<i32>(), 1000);
})
.dispose()
});
runtime.dispose();
}
#[bench]
fn l021_narrowing_update(b: &mut Bencher) {
use l021::*;
let runtime = create_runtime();
b.iter(|| {
create_scope(runtime, |cx| {
let acc = Rc::new(Cell::new(0));
let sigs =
(0..1000).map(|n| create_signal(cx, n)).collect::<Vec<_>>();
let reads = sigs.iter().map(|(r, _)| *r).collect::<Vec<_>>();
let writes = sigs.iter().map(|(_, w)| *w).collect::<Vec<_>>();
let memo = create_memo(cx, move |_| {
reads.iter().map(|r| r.get()).sum::<i32>()
});
assert_eq!(memo(), 499500);
create_isomorphic_effect(cx, {
let acc = Rc::clone(&acc);
move |_| {
acc.set(memo());
}
});
assert_eq!(acc.get(), 499500);
writes[1].update(|n| *n += 1);
writes[10].update(|n| *n += 1);
writes[100].update(|n| *n += 1);
assert_eq!(acc.get(), 499503);
assert_eq!(memo(), 499503);
})
.dispose()
});
runtime.dispose();
}
#[bench]
fn l021_scope_creation_and_disposal(b: &mut Bencher) {
use l021::*;
let runtime = create_runtime();
b.iter(|| {
let acc = Rc::new(Cell::new(0));
let disposers = (0..1000)
.map(|_| {
create_scope(runtime, {
let acc = Rc::clone(&acc);
move |cx| {
let (r, w) = create_signal(cx, 0);
create_isomorphic_effect(cx, {
move |_| {
acc.set(r());
}
});
w.update(|n| *n += 1);
}
})
})
.collect::<Vec<_>>();
for disposer in disposers {
disposer.dispose();
}
});
runtime.dispose();
}
#[bench]
fn sycamore_narrowing_down(b: &mut Bencher) {
use sycamore::reactive::{
create_effect, create_memo, create_scope, create_signal,
};
b.iter(|| {
let d = create_scope(|cx| {
let acc = Rc::new(Cell::new(0));
let sigs = Rc::new((0..1000).map(|n| create_signal(cx, n)).collect::<Vec<_>>());
let sigs = Rc::new(
(0..1000).map(|n| create_signal(cx, n)).collect::<Vec<_>>(),
);
let memo = create_memo(cx, {
let sigs = Rc::clone(&sigs);
move || sigs.iter().map(|r| *r.get()).sum::<i32>()
@@ -97,13 +346,80 @@ fn sycamore_create_1000_signals(b: &mut Bencher) {
}
#[bench]
fn sycamore_create_and_update_1000_signals(b: &mut Bencher) {
use sycamore::reactive::{create_effect, create_memo, create_scope, create_signal};
fn sycamore_fanning_out(b: &mut Bencher) {
use sycamore::reactive::{
create_effect, create_memo, create_scope, create_signal,
};
b.iter(|| {
let d = create_scope(|cx| {
let sig = create_signal(cx, 0);
let memos = (0..1000)
.map(|_| create_memo(cx, move || sig.get()))
.collect::<Vec<_>>();
assert_eq!(memos.iter().map(|m| *(*m.get())).sum::<i32>(), 0);
sig.set(1);
assert_eq!(memos.iter().map(|m| *(*m.get())).sum::<i32>(), 1000);
});
unsafe { d.dispose() };
});
}
#[bench]
fn sycamore_deep_creation(b: &mut Bencher) {
use sycamore::reactive::*;
b.iter(|| {
let d = create_scope(|cx| {
let signal = create_signal(cx, 0);
let mut memos = Vec::<&ReadSignal<usize>>::new();
for i in 0..1000usize {
let prev = memos.get(i.saturating_sub(1)).copied();
if let Some(prev) = prev {
memos.push(create_memo(cx, move || *prev.get() + 1));
} else {
memos.push(create_memo(cx, move || *signal.get() + 1));
}
}
});
unsafe { d.dispose() };
});
}
#[bench]
fn sycamore_deep_update(b: &mut Bencher) {
use sycamore::reactive::*;
b.iter(|| {
let d = create_scope(|cx| {
let signal = create_signal(cx, 0);
let mut memos = Vec::<&ReadSignal<usize>>::new();
for i in 0..1000usize {
let prev = memos.get(i.saturating_sub(1)).copied();
if let Some(prev) = prev {
memos.push(create_memo(cx, move || *prev.get() + 1));
} else {
memos.push(create_memo(cx, move || *signal.get() + 1));
}
}
signal.set(1);
assert_eq!(*memos[999].get(), 1001);
});
unsafe { d.dispose() };
});
}
#[bench]
fn sycamore_narrowing_update(b: &mut Bencher) {
use sycamore::reactive::{
create_effect, create_memo, create_scope, create_signal,
};
b.iter(|| {
let d = create_scope(|cx| {
let acc = Rc::new(Cell::new(0));
let sigs = Rc::new((0..1000).map(|n| create_signal(cx, n)).collect::<Vec<_>>());
let sigs = Rc::new(
(0..1000).map(|n| create_signal(cx, n)).collect::<Vec<_>>(),
);
let memo = create_memo(cx, {
let sigs = Rc::clone(&sigs);
move || sigs.iter().map(|r| *r.get()).sum::<i32>()
@@ -129,7 +445,7 @@ fn sycamore_create_and_update_1000_signals(b: &mut Bencher) {
}
#[bench]
fn sycamore_create_and_dispose_1000_scopes(b: &mut Bencher) {
fn sycamore_scope_creation_and_disposal(b: &mut Bencher) {
use sycamore::reactive::{create_effect, create_scope, create_signal};
b.iter(|| {

View File

@@ -2,12 +2,12 @@ use test::Bencher;
#[bench]
fn leptos_ssr_bench(b: &mut Bencher) {
use leptos::*;
b.iter(|| {
_ = create_scope(|cx| {
b.iter(|| {
use leptos::*;
HydrationCtx::reset_id();
_ = create_scope(create_runtime(), |cx| {
#[component]
fn Counter(cx: Scope, initial: i32) -> Element {
fn Counter(cx: Scope, initial: i32) -> impl IntoView {
let (value, set_value) = create_signal(cx, initial);
view! {
cx,
@@ -28,22 +28,21 @@ fn leptos_ssr_bench(b: &mut Bencher) {
<Counter initial=2/>
<Counter initial=3/>
</main>
};
}.into_view(cx).render_to_string(cx);
assert_eq!(
rendered,
"<main data-hk=\"0-0\"><h1>Welcome to our benchmark page.</h1><p>Here's some introductory text.</p><!--#--><div data-hk=\"0-2-0\"><button>-1</button><span>Value: <!--#-->1<!--/-->!</span><button>+1</button></div><!--/--><!--#--><div data-hk=\"0-3-0\"><button>-1</button><span>Value: <!--#-->2<!--/-->!</span><button>+1</button></div><!--/--><!--#--><div data-hk=\"0-4-0\"><button>-1</button><span>Value: <!--#-->3<!--/-->!</span><button>+1</button></div><!--/--></main>"
);
"<main id=\"_0-1\"><h1 id=\"_0-2\">Welcome to our benchmark page.</h1><p id=\"_0-3\">Here's some introductory text.</p><div id=\"_0-3-1\"><button id=\"_0-3-2\">-1</button><span id=\"_0-3-3\">Value: <!>1<!--hk=_0-3-4-->!</span><button id=\"_0-3-5\">+1</button></div><!--hk=_0-3-0--><div id=\"_0-3-5-1\"><button id=\"_0-3-5-2\">-1</button><span id=\"_0-3-5-3\">Value: <!>2<!--hk=_0-3-5-4-->!</span><button id=\"_0-3-5-5\">+1</button></div><!--hk=_0-3-5-0--><div id=\"_0-3-5-5-1\"><button id=\"_0-3-5-5-2\">-1</button><span id=\"_0-3-5-5-3\">Value: <!>3<!--hk=_0-3-5-5-4-->!</span><button id=\"_0-3-5-5-5\">+1</button></div><!--hk=_0-3-5-5-0--></main>" );
});
});
}
#[bench]
fn tera_ssr_bench(b: &mut Bencher) {
use tera::*;
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};
use tera::*;
static TEMPLATE: &str = r#"<main>
static TEMPLATE: &str = r#"<main>
<h1>Welcome to our benchmark page.</h1>
<p>Here's some introductory text.</p>
{% for counter in counters %}
@@ -55,37 +54,40 @@ fn tera_ssr_bench(b: &mut Bencher) {
{% endfor %}
</main>"#;
lazy_static::lazy_static! {
static ref TERA: Tera = {
let mut tera = Tera::default();
tera.add_raw_templates(vec![("template.html", TEMPLATE)]).unwrap();
tera
};
}
lazy_static::lazy_static! {
static ref TERA: Tera = {
let mut tera = Tera::default();
tera.add_raw_templates(vec![("template.html", TEMPLATE)]).unwrap();
tera
};
}
#[derive(Serialize, Deserialize)]
struct Counter {
value: i32
}
#[derive(Serialize, Deserialize)]
struct Counter {
value: i32,
}
b.iter(|| {
let mut ctx = Context::new();
ctx.insert("counters", &vec![
Counter { value: 0 },
Counter { value: 1},
Counter { value: 2 }
]);
b.iter(|| {
let mut ctx = Context::new();
ctx.insert(
"counters",
&vec![
Counter { value: 0 },
Counter { value: 1 },
Counter { value: 2 },
],
);
let _ = TERA.render("template.html", &ctx).unwrap();
});
let _ = TERA.render("template.html", &ctx).unwrap();
});
}
#[bench]
fn sycamore_ssr_bench(b: &mut Bencher) {
use sycamore::*;
use sycamore::prelude::*;
use sycamore::prelude::*;
use sycamore::*;
b.iter(|| {
b.iter(|| {
_ = create_scope(|cx| {
#[derive(Prop)]
struct CounterProps {
@@ -139,10 +141,10 @@ fn sycamore_ssr_bench(b: &mut Bencher) {
#[bench]
fn yew_ssr_bench(b: &mut Bencher) {
use yew::prelude::*;
use yew::ServerRenderer;
use yew::prelude::*;
use yew::ServerRenderer;
b.iter(|| {
b.iter(|| {
#[derive(Properties, PartialEq, Eq, Debug)]
struct CounterProps {
initial: i32

View File

@@ -1,4 +1,4 @@
use leptos::*;
pub use leptos::*;
use miniserde::*;
use web_sys::HtmlInputElement;
@@ -97,7 +97,7 @@ const ESCAPE_KEY: u32 = 27;
const ENTER_KEY: u32 = 13;
#[component]
pub fn TodoMVC(cx: Scope, todos: Todos) -> Element {
pub fn TodoMVC(cx: Scope, todos: Todos) -> impl IntoView {
let mut next_id = todos
.0
.iter()
@@ -115,7 +115,7 @@ pub fn TodoMVC(cx: Scope, todos: Todos) -> Element {
set_mode(new_mode);
});
let add_todo = move |ev: web_sys::Event| {
let add_todo = move |ev: web_sys::KeyboardEvent| {
let target = event_target::<HtmlInputElement>(&ev);
ev.stop_propagation();
let key_code = ev.unchecked_ref::<web_sys::KeyboardEvent>().key_code();
@@ -167,62 +167,64 @@ pub fn TodoMVC(cx: Scope, todos: Todos) -> Element {
});
view! { cx,
<main>
<section class="todoapp">
<header class="header">
<h1>"todos"</h1>
<input class="new-todo" placeholder="What needs to be done?" autofocus on:keydown=add_todo />
</header>
<section class="main" class:hidden={move || todos.with(|t| t.is_empty())}>
<input id="toggle-all" class="toggle-all" type="checkbox"
prop:checked={move || todos.with(|t| t.remaining() > 0)}
on:input=move |_| set_todos.update(|t| t.toggle_all())
/>
<label for="toggle-all">"Mark all as complete"</label>
<ul class="todo-list">
<For each=filtered_todos key=|todo| todo.id>
{move |cx, todo: &Todo| view! { cx, <Todo todo=todo.clone() /> }}
</For>
</ul>
</section>
<footer class="footer" class:hidden={move || todos.with(|t| t.is_empty())}>
<span class="todo-count">
<strong>{move || todos.with(|t| t.remaining().to_string())}</strong>
{move || if todos.with(|t| t.remaining()) == 1 {
" item"
} else {
" items"
}}
" left"
</span>
<ul class="filters">
<li><a href="#/" class="selected" class:selected={move || mode() == Mode::All}>"All"</a></li>
<li><a href="#/active" class:selected={move || mode() == Mode::Active}>"Active"</a></li>
<li><a href="#/completed" class:selected={move || mode() == Mode::Completed}>"Completed"</a></li>
</ul>
<button
class="clear-completed hidden"
class:hidden={move || todos.with(|t| t.completed() == 0)}
on:click=move |_| set_todos.update(|t| t.clear_completed())
>
"Clear completed"
</button>
</footer>
</section>
<footer class="info">
<p>"Double-click to edit a todo"</p>
<p>"Created by "<a href="http://todomvc.com">"Greg Johnston"</a></p>
<p>"Part of "<a href="http://todomvc.com">"TodoMVC"</a></p>
</footer>
</main>
}
<main>
<section class="todoapp">
<header class="header">
<h1>"todos"</h1>
<input class="new-todo" placeholder="What needs to be done?" autofocus="" on:keydown=add_todo />
</header>
<section class="main" class:hidden={move || todos.with(|t| t.is_empty())}>
<input id="toggle-all" class="toggle-all" type="checkbox"
prop:checked={move || todos.with(|t| t.remaining() > 0)}
on:input=move |_| set_todos.update(|t| t.toggle_all())
/>
<label for="toggle-all">"Mark all as complete"</label>
<ul class="todo-list">
<For
each=filtered_todos
key=|todo| todo.id
view=move |todo: Todo| view! { cx, <Todo todo=todo.clone() /> }
/>
</ul>
</section>
<footer class="footer" class:hidden={move || todos.with(|t| t.is_empty())}>
<span class="todo-count">
<strong>{move || todos.with(|t| t.remaining().to_string())}</strong>
{move || if todos.with(|t| t.remaining()) == 1 {
" item"
} else {
" items"
}}
" left"
</span>
<ul class="filters">
<li><a href="#/" class="selected" class:selected={move || mode() == Mode::All}>"All"</a></li>
<li><a href="#/active" class:selected={move || mode() == Mode::Active}>"Active"</a></li>
<li><a href="#/completed" class:selected={move || mode() == Mode::Completed}>"Completed"</a></li>
</ul>
<button
class="clear-completed hidden"
class:hidden={move || todos.with(|t| t.completed() == 0)}
on:click=move |_| set_todos.update(|t| t.clear_completed())
>
"Clear completed"
</button>
</footer>
</section>
<footer class="info">
<p>"Double-click to edit a todo"</p>
<p>"Created by "<a href="http://todomvc.com">"Greg Johnston"</a></p>
<p>"Part of "<a href="http://todomvc.com">"TodoMVC"</a></p>
</footer>
</main>
}.into_view(cx)
}
#[component]
pub fn Todo(cx: Scope, todo: Todo) -> Element {
pub fn Todo(cx: Scope, todo: Todo) -> impl IntoView {
let (editing, set_editing) = create_signal(cx, false);
let set_todos = use_context::<WriteSignal<Todos>>(cx).unwrap();
let input: Element;
//let input = NodeRef::new(cx);
let save = move |value: &str| {
let value = value.trim();
@@ -234,12 +236,12 @@ pub fn Todo(cx: Scope, todo: Todo) -> Element {
set_editing(false);
};
let tpl = view! { cx,
view! { cx,
<li
class="todo"
class:editing={editing}
class:completed={move || (todo.completed)()}
_ref=input
//_ref=input
>
<div class="view">
<input
@@ -271,9 +273,7 @@ pub fn Todo(cx: Scope, todo: Todo) -> Element {
})
}
</li>
};
tpl
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

View File

@@ -7,15 +7,16 @@ mod yew;
#[bench]
fn leptos_todomvc_ssr(b: &mut Bencher) {
use self::leptos::*;
use ::leptos::*;
b.iter(|| {
_ = create_scope(|cx| {
use crate::todomvc::leptos::*;
_ = create_scope(create_runtime(), |cx| {
let rendered = view! {
cx,
<TodoMVC todos=Todos::new(cx)/>
};
}
.into_view(cx)
.render_to_string(cx);
assert!(rendered.len() > 1);
});
@@ -56,18 +57,18 @@ fn yew_todomvc_ssr(b: &mut Bencher) {
});
});
}
/*
#[bench]
fn leptos_todomvc_ssr_with_1000(b: &mut Bencher) {
use self::leptos::*;
use ::leptos::*;
b.iter(|| {
_ = create_scope(|cx| {
use self::leptos::*;
use ::leptos::*;
_ = create_scope(create_runtime(), |cx| {
let rendered = view! {
cx,
<TodoMVC todos=Todos::new_with_1000(cx)/>
};
}.into_view(cx).render_to_string(cx);
assert!(rendered.len() > 1);
});
@@ -108,3 +109,4 @@ fn yew_todomvc_ssr_with_1000(b: &mut Bencher) {
});
});
}
*/

63
docs/COMMON_BUGS.md Normal file
View File

@@ -0,0 +1,63 @@
# Leptos Gotchas: Common Bugs
This document is intended as a running list of common issues, with example code and solutions.
## Reactivity
### Avoid writing to a signal from an effect
**Issue**: Sometimes you want to update a reactive signal in a way that depends on another signal.
```rust
let (a, set_a) = create_signal(cx, 0);
let (b, set_b) = create_signal(cx, false);
create_effect(cx, move |_| {
if a() > 5 {
set_b(true);
}
});
```
This creates an inefficient chain of updates, and can easily lead to infinite loops in more complex applications.
**Solution**: Follow the rule, _What can be derived, should be derived._ In this case, this has the benefit of massively reducing the code size, too!
```rust
let (a, set_a) = create_signal(cx, 0);
let b = move || a () > 5;
```
## Templates and the DOM
### `<input value=...>` doesn't update or stops updating
Many DOM attributes can be updated either by setting an attribute on the DOM node, or by setting an object property directly on it. In general, `setAttribute()` stops working once the property has been set.
This means that in practice, attributes like `value` or `checked` on an `<input/>` element only update the _default_ value for the `<input/>`. If you want to reactively update the value, you should use `prop:value` instead to set the `value` property.
```rust
let (a, set_a) = create_signal(cx, "Starting value".to_string());
let on_input = move |ev| set_a(event_target_value(&ev));
view! {
cx,
// ❌ reactivity doesn't work as expected: typing only updates the default
// of each input, so if you start typing in the second input, it won't
// update the first one
<input value=a on:input=on_input />
<input value=a on:input=on_input />
}
```
```rust
let (a, set_a) = create_signal(cx, "Starting value".to_string());
let on_input = move |ev| set_a(event_target_value(&ev));
view! {
cx,
// ✅ works as intended by setting the value *property*
<input prop:value=a on:input=on_input />
<input prop:value=a on:input=on_input />
}
```

View File

@@ -1 +1 @@
book
book

14
docs/book/README.md Normal file
View File

@@ -0,0 +1,14 @@
This project contains the core of a new introductory guide to Leptos.
It is built using `mdbook`. You can view a local copy by installing `mdbook`
```bash
cargo install mdbook
```
and run the book with
```
mdbook serve
```
It should be available at `http://localhost:3000`.

View File

@@ -1,6 +0,0 @@
[book]
authors = ["Greg Johnston"]
language = "en"
multilingual = false
src = "src"
title = "The Leptos Guide"

View File

@@ -1,12 +0,0 @@
[package]
name = "ch01_getting_started"
version = "0.1.0"
edition = "2021"
[dependencies]
leptos = { version = "0.0", features = ["csr"] }
[profile.release]
codegen-units = 1
lto = true
opt-level = 'z'

View File

@@ -1,10 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Leptos • Todos</title>
<link data-trunk rel="rust" data-wasm-opt="z" />
</head>
<body></body>
</html>

View File

@@ -1,5 +0,0 @@
use leptos::*;
fn main() {
mount_to_body(|cx| view! { cx, <p>"Hello, world!"</p> })
}

View File

@@ -0,0 +1,20 @@
# Introduction
This book is intended as an introduction to the [Leptos](https://github.com/leptos-rs/leptos) Web framework.
It will walk through the fundamental concepts you need to build applications,
beginning with a simple application rendered in the browser, and building toward a
full-stack application with server-side rendering and hydration.
The guide doesnt assume you know anything about fine-grained reactivity or the
details of modern Web frameworks. It does assume you are familiar with the Rust
programming language, HTML, CSS, and the DOM and basic Web APIs.
Leptos is most similar to frameworks like [Solid](https://www.solidjs.com) (JavaScript)
and [Sycamore](https://sycamore-rs.netlify.app/) (Rust). There are some similarities
to other frameworks like React (JavaScript), Svelte (JavaScript), Yew (Rust), and
Dioxus (Rust), so knowledge of one of those frameworks may also make it easier to
understand Leptos.
You can find more detailed docs for each part of the API at [Docs.rs](https://docs.rs/leptos/latest/leptos/).
**The guide is a work in progress.**

View File

@@ -0,0 +1,70 @@
# Getting Started
There are two basic paths to getting started with Leptos:
1. Client-side rendering with [Trunk](https://trunkrs.dev/)
2. Full-stack rendering with [`cargo-leptos`](https://github.com/leptos-rs/cargo-leptos)
For the early examples, it will be easiest to begin with Trunk. Well introduce
`cargo-leptos` a little later in this series.
If you dont already have it installed, you can install Trunk by running
```bash
cargo install trunk
```
Create a basic Rust binary project
```bash
cargo init leptos-tutorial
```
> We recommend using `nightly` Rust, as it enables [a few nice features](https://github.com/leptos-rs/leptos#nightly-note). To use `nightly` Rust with WebAssembly, you can run
>
> ```bash
> rustup toolchain install nightly
> rustup default nightly
> rustup target add wasm32-unknown-unknown
> ```
`cd` into your new `leptos-tutorial` project and add `leptos` as a dependency
```bash
cargo add leptos
```
Create a simple `index.html` in the root of the `leptos-tutorial` directory
```html
<!DOCTYPE html>
<html>
<head></head>
<body></body>
</html>
```
And add a simple “Hello, world!” to your `main.rs`
```rust
use leptos::*;
fn main() {
mount_to_body(|cx| view! { cx, <p>"Hello, world!"</p> })
}
```
Your directory structure should now look something like this
```
leptos_tutorial
├── src
│ └── main.rs
├── Cargo.toml
├── index.html
```
Now run `trunk serve --open` from the root of the `leptos-tutorial` directory.
Trunk should automatically compile your app and open it in your default browser.
If you make edits to `main.rs`, Trunk will recompile your source code and
live-reload the page.

View File

@@ -0,0 +1,110 @@
# Responding to Changes with `create_effect`
Believe it or not, weve made it this far without having mentioned half of the reactive system: effects.
Leptos is built on a fine-grained reactive system, which means that individual reactive values (“signals,” sometimes known as observables) trigger rerunning the code that reacts to them (“effects,” sometimes known as observers). These two halves of the reactive system are inter-dependent. Without effects, signals can change within the reactive system but never be observed in a way that interacts with the outside world. Without signals, effects run once but never again, as theres no observable value to subscribe to.
[`create_effect`](https://docs.rs/leptos_reactive/latest/leptos_reactive/fn.create_effect.html) takes a function as its argument. It immediately runs the function. If you access any reactive signal inside that function, it registers the fact that the effect depends on that signal with the reactive runtime. Whenever one of the signals that the effect depends on changes, the effect runs again.
```rust
let (a, set_a) = create_signal(cx, 0);
let (b, set_b) = create_signal(cx, 0);
create_effect(cx, move |_| {
// immediately prints "Value: 0" and subscribes to `a`
log::debug!("Value: {}", a());
});
```
The effect function is called with an argument containing whatever value it returned the last time it ran. On the initial run, this is `None`.
By default, effects **do not run on the server**. This means you can call browser-specific APIs within the effect function without causing issues. If you need an effect to run on the server, use [`create_isomorphic_effect`](https://docs.rs/leptos_reactive/latest/leptos_reactive/fn.create_isomorphic_effect.html).
## Autotracking and Dynamic Dependencies
If youre familiar with a framework like React, you might notice one key difference. React and similar frameworks typically require you to pass a “dependency array,” an explicit set of variables that determine when the effect should rerun.
Because Leptos comes from the tradition of synchronous reactive programming, we dont need this explicit dependency list. Instead, we automatically track dependencies depending on which signals are accessed within the effect.
This has two effects (no pun intended). Dependencies are
1. **Automatic**: You dont need to maintain a dependency list, or worry about what should or shouldnt be included. The framework simply tracks which signals might cause the effect to rerun, and handles it for you.
2. **Dynamic**: The dependency list is cleared and updated every time the effect runs. If your effect contains a conditional (for example), only signals that are used in the current branch are tracked. This means that effects rerun the absolute minimum number of times.
> If this sounds like magic, and if you want a deep dive into how automatic dependency tracking works, [check out this video](https://www.youtube.com/watch?v=GWB3vTWeLd4). (Apologies for the low volume!)
## Effects as Zero-Cost-ish Abstraction
While theyre not a “zero-cost abstraction” in the most technical sense—they require some additional memory use, exist at runtime, etc.—at a higher level, from the perspective of whatever expensive API calls or other work youre doing within them, effects are a zero-cost abstraction. They rerun the absolute minimum number of times necessary, given how youve described them.
Imagine that Im creating some kind of chat software, and I want people to be able to display their full name, or just their first name, and to notify the server whenever their name changes:
```rust
let (first, set_first) = create_signal(cx, String::new());
let (last, set_last) = create_signal(cx, String::new());
let (use_last, set_use_last) = create_signal(cx, true);
// this will add the name to the log
// any time one of the source signals changes
create_effect(cx, move |_| {
log(
cx,
if use_last() {
format!("{} {}", first(), last())
} else {
first()
},
)
});
```
If `use_last` is `true`, effect should rerun whenever `first`, `last`, or `use_last` changes. But if I toggle `use_last` to `false`, a change in `last` will never cause the full name to change. In fact, `last` will be removed from the dependency list until `use_last` toggles again. This saves us from sending multiple unnecessary requests to the API if I change `last` multiple times while `use_last` is still `false`.
## To `create_effect`, or not to `create_effect`?
Effects are intended to run _side-effects_ of the system, not to synchronize state _within_ the system. In other words: dont write to signals within effects.
If you need to define a signal that depends on the value of other signals, use a derived signal or [`create_memo`](https://docs.rs/leptos_reactive/latest/leptos_reactive/fn.create_memo.html).
If you need to synchronize some reactive value with the non-reactive world outside—like a web API, the console, the filesystem, or the DOM—create an effect.
> If youre curious for more information about when you should and shouldnt use `create_effect`, [check out this video](https://www.youtube.com/watch?v=aQOFJQ2JkvQ) for a more in-depth consideration!
## Effects and Rendering
Weve managed to get this far without mentioning effects because theyre built into the Leptos DOM renderer. Weve seen that you can create a signal and pass it into the `view` macro, and it will update the relevant DOM node whenever the signal changes:
```rust
let (count, set_count) = create_signal(cx, 0);
view! { cx,
<p>{count}</p>
}
```
This works because the framework essentially creates an effect wrapping this update. You can imagine Leptos translating this view into something like this:
```rust
let (count, set_count) = create_signal(cx, 0);
// create a DOM element
let p = create_element("p");
// create an effect to reactively update the text
create_effect(cx, move |prev_value| {
// first, access the signals value and convert it to a string
let text = count().to_string();
// if this is different from the previous value, update the node
if prev_value != Some(text) {
p.set_text_content(&text);
}
// return this value so we can memoize the next update
text
});
```
Every time `count` is updated, this effect wil rerun. This is what allows reactive, fine-grained updates to the DOM.
<iframe src="https://codesandbox.io/p/sandbox/serene-thompson-40974n?file=%2Fsrc%2Fmain.rs&selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A2%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A2%7D%5D" width="100%" height="1000px"></iframe>

View File

@@ -0,0 +1,171 @@
# Global State Management
So far, we've only been working with local state in components
We've only seen how to communicate between parent and child components
But there are also more general ways to manage global state
The three best approaches to global state are
1. Using the router to drive global state via the URL
2. Passing signals through context
3. Creating a global state struct and creating lenses into it with `create_slice`
## Option #1: URL as Global State
The next few sections of the tutorial will be about the router.
So for now, we'll just look at options #2 and #3.
## Option #2: Passing Signals through Context
In virtual DOM libraries like React, using the Context API to manage global
state is a bad idea: because the entire app exists in a tree, changing
some value provided high up in the tree can cause the whole app to render.
In fine-grained reactive libraries like Leptos, this is simply not the case.
You can create a signal in the root of your app and pass it down to other
components using provide_context(). Changing it will only cause rerendering
in the specific places it is actually used, not the whole app.
We start by creating a signal in the root of the app and providing it to
all its children and descendants using `provide_context`.
```rust
#[component]
fn App(cx: Scope) -> impl IntoView {
// here we create a signal in the root that can be consumed
// anywhere in the app.
let (count, set_count) = create_signal(cx, 0);
// we'll pass the setter to specific components,
// but provide the count itself to the whole app via context
provide_context(cx, count);
view! { cx,
// SetterButton is allowed to modify the count
<SetterButton set_count/>
// These consumers can only read from it
// But we could give them write access by passing `set_count` if we wanted
<FancyMath/>
<ListItems/>
}
}
```
`<SetterButton/>` is the kind of counter weve written several times now.
(See the sandbox below if you dont understand what I mean.)
`<FancyMath/>` and `<ListItems/>` both consume the signal were providing via
`use_context` and do something with it.
```rust
/// A component that does some "fancy" math with the global count
#[component]
fn FancyMath(cx: Scope) -> impl IntoView {
// here we consume the global count signal with `use_context`
let count = use_context::<ReadSignal<u32>>(cx)
// we know we just provided this in the parent component
.expect("there to be a `count` signal provided");
let is_even = move || count() & 1 == 0;
view! { cx,
<div class="consumer blue">
"The number "
<strong>{count}</strong>
{move || if is_even() {
" is"
} else {
" is not"
}}
" even."
</div>
}
}
```
This kind of “provide a signal in a parent, consume it in a child” should be familiar
from the chapter on [parent-child interactions](./view/08_parent_child.md). The same
pattern you use to communicate between parents and children works for grandparents and
grandchildren, or any ancestors and descendents: in other words, between “global” state
in the root component of your app and any other components anywhere else in the app.
Because of the fine-grained nature of updates, this is usually all you need. However,
in some cases with more complex state changes, you may want to use a slightly more
structured approach to global state.
## Option #3: Create a Global State Struct
You can use this approach to build a single global data structure
that holds the state for your whole app, and then access it by
taking fine-grained slices using
[`create_slice`](https://docs.rs/leptos/latest/leptos/fn.create_slice.html)
or [`create_memo`](https://docs.rs/leptos/latest/leptos/fn.create_memo.html),
so that changing one part of the state doesn't cause parts of your
app that depend on other parts of the state to change.
You can begin by defining a simple state struct:
```rust
#[derive(Default, Clone, Debug)]
struct GlobalState {
count: u32,
name: String,
}
```
Provide it in the root of your app so its available everywhere.
```rust
#[component]
fn App(cx: Scope) -> impl IntoView {
// we'll provide a single signal that holds the whole state
// each component will be responsible for creating its own "lens" into it
let state = create_rw_signal(cx, GlobalState::default());
provide_context(cx, state);
// ...
```
Then child components can access “slices” of that state with fine-grained
updates via `create_slice`. Each slice signal only updates when the particular
piece of the larger struct it accesses updates. This means you can create a single
root signal, and then take independent, fine-grained slices of it in different
components, each of which can update without notifying the others of changes.
```rust
/// A component that updates the count in the global state.
#[component]
fn GlobalStateCounter(cx: Scope) -> impl IntoView {
let state = use_context::<RwSignal<GlobalState>>(cx).expect("state to have been provided");
// `create_slice` lets us create a "lens" into the data
let (count, set_count) = create_slice(
cx,
// we take a slice *from* `state`
state,
// our getter returns a "slice" of the data
|state| state.count,
// our setter describes how to mutate that slice, given a new value
|state, n| state.count = n,
);
view! { cx,
<div class="consumer blue">
<button
on:click=move |_| {
set_count(count() + 1);
}
>
"Increment Global Count"
</button>
<br/>
<span>"Count is: " {count}</span>
</div>
}
}
```
Clicking this button only updates `state.count`, so if we create another slice
somewhere else that only takes `state.name`, clicking the button wont cause
that other slice to update. This allows you to combine the benefits of a top-down
data flow and of fine-grained reactive updates.
<iframe src="https://codesandbox.io/p/sandbox/1-basic-component-forked-8bte19?selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A2%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A2%7D%5D&file=%2Fsrc%2Fmain.rs" width="100%" height="1000px">

View File

@@ -1,6 +1,48 @@
# Summary
- [Introduction](./introduction.md)
- [Getting Started](./getting_started.md)
- [Templating: Building User Interfaces](./building_ui.md)
- [Reactivity: Making Things Interactive](./reactivity.md)
- [Introduction](./01_introduction.md)
- [Getting Started](./02_getting_started.md)
- [Building User Interfaces](./view/README.md)
- [A Basic Component](./view/01_basic_component.md)
- [Dynamic Attributes](./view/02_dynamic_attributes.md)
- [Components and Props](./view/03_components.md)
- [Iteration](./view/04_iteration.md)
- [Forms and Inputs](./view/05_forms.md)
- [Control Flow](./view/06_control_flow.md)
- [Error Handling](./view/07_errors.md)
- [Parent-Child Communication](./view/08_parent_child.md)
- [Passing Children to Components](./view/09_component_children.md)
- [Interlude: Reactivity and Functions](./interlude_functions.md)
- [Testing](./testing.md)
- [Async](./async/README.md)
- [Loading Data with Resources](./async/10_resources.md)
- [Suspense](./async/11_suspense.md)
- [Transition](./async/12_transition.md)
- [Actions](./async/13_actions.md)
- [Responding to Changes with `create_effect`](./14_create_effect.md)
- [Global State Management](./15_global_state.md)
- [Router](./router/README.md)
- [Defining `<Routes/>`](./router/16_routes.md)
- [Nested Routing](./router/17_nested_routing.md)
- [Params and Queries](./router/18_params_and_queries.md)
- [`<A/>`](./router/19_a.md)
- [`<Form/>`]()
- [Interlude: Styling — CSS, Tailwind, Style.rs, and more]()
- [Metadata]()
- [SSR]()
- [Models of SSR]()
- [`cargo-leptos`]()
- [Hydration Footguns]()
- [Request/Response]()
- [Extractors]()
- [Axum]()
- [Actix]()
- [Headers]()
- [Cookies]()
- [Server Functions]()
- [Actions]()
- [Forms]()
- [`<ActionForm/>`s]()
- [Turning off WebAssembly]()
- [Advanced Reactivity]()
- [Appendix: Optimizing WASM Binary Size]()

View File

@@ -0,0 +1,53 @@
# Loading Data with Resources
A [Resource](https://docs.rs/leptos/latest/leptos/struct.Resource.html) is a reactive data structure that reflects the current state of an asynchronous task, allowing you to integrate asynchronous `Future`s into the synchronous reactive system. Rather than waiting for its data to load with `.await`, you transform the `Future` into a signal that returns `Some(T)` if it has resolved, and `None` if its still pending.
You do this by using the [`create_resource`](https://docs.rs/leptos/latest/leptos/fn.create_resource.html) function. This takes two arguments (other than the ubiquitous `cx`):
1. a source signal, which will generate a new `Future` whenever it changes
2. a fetcher function, which takes the data from that signal and returns a `Future`
Heres an example
```rust
// our source signal: some synchronous, local state
let (count, set_count) = create_signal(cx, 0);
// our resource
let async_data = create_resource(cx,
count,
// every time `count` changes, this will run
|value| async move {
log!("loading data from API");
load_data(value).await
},
);
```
To create a resource that simply runs once, you can pass a non-reactive, empty source signal:
```rust
let once = create_resource(cx, || (), |_| async move { load_data().await });
```
To access the value you can use `.read(cx)` or `.with(cx, |data| /* */)`. These work just like `.get()` and `.with()` on a signal—`read` clones the value and returns it, `with` applies a closure to it—but with two differences
1. For any `Resource<_, T>`, they always return `Option<T>`, not `T`: because its always possible that your resource is still loading.
2. They take a `Scope` argument. Youll see why in the next chapter, on `<Suspense/>`.
So, you can show the current state of a resource in your view:
```rust
let once = create_resource(cx, || (), |_| async move { load_data().await });
view! { cx,
<h1>"My Data"</h1>
{move || match once.read(cx) {
None => view! { cx, <p>"Loading..."</p> }.into_view(cx),
Some(data) => view! { cx, <ShowData data/> }.into_view(cx)
}}
}
```
Resources also provide a `refetch()` method that allows you to manually reload the data (for example, in response to a button click) and a `loading()` method that returns a `ReadSignal<bool>` indicating whether the resource is currently loading or not.
<iframe src="https://codesandbox.io/p/sandbox/10-async-resources-4z0qt3?file=%2Fsrc%2Fmain.rs&selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A3%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A3%7D%5D" width="100%" height="1000px"></iframe>

View File

@@ -0,0 +1,72 @@
# `<Suspense/>`
In the previous chapter, we showed how you can create a simple loading screen to show some fallback while a resource is loading.
```rust
let (count, set_count) = create_signal(cx, 0);
let a = create_resource(cx, count, |count| async move { load_a(count).await });
view! { cx,
<h1>"My Data"</h1>
{move || match once.read(cx) {
None => view! { cx, <p>"Loading..."</p> }.into_view(cx),
Some(data) => view! { cx, <ShowData data/> }.into_view(cx)
}}
}
```
But what if we have two resources, and want to wait for both of them?
```rust
let (count, set_count) = create_signal(cx, 0);
let (count2, set_count2) = create_signal(cx, 0);
let a = create_resource(cx, count, |count| async move { load_a(count).await });
let b = create_resource(cx, count2, |count| async move { load_b(count).await });
view! { cx,
<h1>"My Data"</h1>
{move || match (a.read(cx), b.read(cx)) {
_ => view! { cx, <p>"Loading..."</p> }.into_view(cx),
(Some(a), Some(b)) => view! { cx,
<ShowA a/>
<ShowA b/>
}.into_view(cx)
}}
}
```
Thats not _so_ bad, but its kind of annoying. What if we could invert the flow of control?
The [`<Suspense/>`](https://docs.rs/leptos/latest/leptos/fn.Suspense.html) component lets us do exactly that. You give it a `fallback` prop and children, one or more of which usually involves reading from a resource. Reading from a resource “under” a `<Suspense/>` (i.e., in one of its children) registers that resource with the `<Suspense/>`. If its still waiting for resources to load, it shows the `fallback`. When theyve all loaded, it shows the children.
```rust
let (count, set_count) = create_signal(cx, 0);
let (count2, set_count2) = create_signal(cx, 0);
let a = create_resource(cx, count, |count| async move { load_a(count).await });
let b = create_resource(cx, count2, |count| async move { load_b(count).await });
view! { cx,
<h1>"My Data"</h1>
<Suspense
fallback=move || view! { cx, <p>"Loading..."</p> }
>
<h2>"My Data"</h2>
<h3>"A"</h3>
{move || {
a.read(cx)
.map(|a| view! { cx, <ShowA a/> })
}}
<h3>"B"</h3>
{move || {
b.read(cx)
.map(|b| view! { cx, <ShowB b/> })
}}
</Suspense>
}
```
Every time one of the resources is reloading, the `"Loading..."` fallback will show again.
This inversion of the flow of control makes it easier to add or remove individual resources, as you dont need to handle the matching yourself. It also unlocks some massive performance improvements during server-side rendering, which well talk about during a later chapter.
<iframe src="https://codesandbox.io/p/sandbox/11-suspense-907niv?file=%2Fsrc%2Fmain.rs" width="100%" height="1000px"></iframe>

View File

@@ -0,0 +1,9 @@
# `<Transition/>`
Youll notice in the `<Suspense/>` example that if you keep reloading the data, it keeps flickering back to `"Loading..."`. Sometimes this is fine. For other times, theres [`<Transition/>`](https://docs.rs/leptos/latest/leptos/fn.Suspense.html).
`<Transition/>` behaves exactly the same as `<Suspense/>`, but instead of falling back every time, it only shows the fallback the first time. On all subsequent loads, it continues showing the old data until the new data are ready. This can be really handy to prevent the flickering effect, and to allow users to continue interacting with your application.
This example shows how you can create a simple tabbed contact list with `<Transition/>`. When you select a new tab, it continues showing the current contact until the new data laods. This can be a much better user experience than constantly falling back to a loading message.
<iframe src="https://codesandbox.io/p/sandbox/12-transition-sn38sd?selection=%5B%7B%22endColumn%22%3A15%2C%22endLineNumber%22%3A2%2C%22startColumn%22%3A15%2C%22startLineNumber%22%3A2%7D%5D&file=%2Fsrc%2Fmain.rs" width="100%" height="1000px"></iframe>

View File

@@ -0,0 +1,94 @@
# Mutating Data with Actions
Weve talked about how to load `async` data with resources. Resources immediately load data and work closely with `<Suspense/>` and `<Transition/>` components to show whether data is loading in your app. But what if you just want to call some arbitrary `async` function and keep track of what its doing?
Well, you could always use [`spawn_local`](https://docs.rs/leptos/latest/leptos/fn.spawn_local.html). This allows you to just spawn an `async` task in a synchronous environment by handing the `Future` off to the browser (or, on the server, Tokio or whatever other runtime youre using). But how do you know if its still pending? Well, you could just set a signal to show whether its loading, and another one to show the result...
All of this is true. Or you could use the final `async` primitive: [`create_action`](https://docs.rs/leptos/latest/leptos/fn.create_action.html).
Actions and resources seem similar, but they represent fundamentally different things. If youre trying to load data by running an `async` function, either once or when some other value changes, you probably want to use `create_resource`. If youre trying to occasionally run an `async` function in response to something like a user clicking a button, you probably want to use `create_action`.
Say we have some `async` function we want to run.
```rust
async fn add_todo(new_title: &str) -> Uuid {
/* do some stuff on the server to add a new todo */
}
```
`create_action` takes a reactive `Scope` and an `async` function that takes a reference to a single argument, which you could think of as its “input type.”
> The input is always a single type. If you want to pass in multiple arguments, you can do it with a struct or tuple.
>
> ```rust
> // if there's a single argument, just use that
> let action1 = create_action(cx, |input: &String| {
> let input = input.clone();
> async move { todo!() }
> });
>
> // if there are no arguments, use the unit type `()`
> let action2 = create_action(cx, |input: &()| async { todo!() });
>
> // if there are multiple arguments, use a tuple
> let action3 = create_action(cx,
> |input: &(usize, String)| async { todo!() }
> );
> ```
>
> Because the action function takes a reference but the `Future` needs to have a `'static` lifetime, youll usually need to clone the value to pass it into the `Future`. This is admittedly awkward but it unlocks some powerful features like optimistic UI. Well see a little more about that in future chapters.
So in this case, all we need to do to create an action is
```rust
let add_todo = create_action(cx, |input: &String| {
let input = input.to_owned();
async move { add_todo(&input).await }
});
```
Rather than calling `add_todo` directly, well call it with `.dispatch()`, as in
```rust
add_todo.dispatch("Some value".to_string());
```
You can do this from an event listener, a timeout, or anywhere; because `.dispatch()` isnt an `async` function, it can be called from a synchronous context.
Actions provide access to a few signals that synchronize between the asynchronous action youre calling and the synchronous reactive system:
```rust
let submitted = add_todo.input(); // RwSignal<Option<String>>
let pending = add_todo.pending(); // ReadSignal<bool>
let todo_id = add_todo.value(); // RwSignal<Option<Uuid>>
```
This makes it easy to track the current state of your request, show a loading indicator, or do “optimistic UI” based on the assumption that the submission will succeed.
```rust
let input_ref = create_node_ref::<Input>(cx);
view! { cx,
<form
on:submit=move |ev| {
ev.prevent_default(); // don't reload the page...
let input = input_ref.get().expect("input to exist");
add_todo.dispatch(input.value());
}
>
<label>
"What do you need to do?"
<input type="text"
node_ref=input_ref
/>
</label>
<button type="submit">"Add Todo"</button>
</form>
// use our loading state
<p>{move || pending().then("Loading...")}</p>
}
```
Now, theres a chance this all seems a little over-complicated, or maybe too restricted. I wanted to include actions here, alongside resources, as the missing piece of the puzzle. In a real Leptos app, youll actually most often use actions alongside server functions, [`create_server_action`](https://docs.rs/leptos/latest/leptos/fn.create_server_action.html), and the [`<ActionForm/>`](https://docs.rs/leptos_router/latest/leptos_router/fn.ActionForm.html) component to create really powerful progressively-enhanced forms. So if this primitive seems useless to you... Dont worry! Maybe it will make sense later. (Or check out our [`todo_app_sqlite`](https://github.com/leptos-rs/leptos/blob/main/examples/todo_app_sqlite/src/todo.rs) example now.)
<iframe src="https://codesandbox.io/p/sandbox/10-async-resources-forked-hgpfp0?selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A4%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A4%7D%5D&file=%2Fsrc%2Fmain.rs" width="100%" height="1000px"></iframe>

View File

@@ -0,0 +1,9 @@
# Working with `async`
So far weve only been working with synchronous users interfaces: You provide some input,
the app immediately process it and updates the interface. This is great, but is a tiny
subset of what web applications do. In particular, most web apps have to deal with some kind
of asynchronous data loading, usually loading something from an API.
Asynchronous data is notoriously hard to integrate with the synchronous parts of your code.
In this chapter, well see how Leptos helps smooth out that process for you.

View File

@@ -1,49 +0,0 @@
# Templating: Building User Interfaces
## Views
Leptos uses a simple `view` macro to create the user interface. If youre familiar with JSX, then
## Components
**Components** are the basic building blocks of your application. Each component is simply a function that creates DOM nodes and sets up the reactive system that will update them. The component function runs exactly once per instance of the component.
The `component` macro annotates a function as a component, allowing you to use it within other components.
```rust
use leptos::*;
#[component]
fn Button(cx: Scope, text: &'static str) -> Element {
view! { cx,
<button>{text}</button>
}
}
#[component]
fn BoringButtons(cx: Scope) -> Element {
view! { cx,
<div>
<Button text="These"/>
<Button text="Do"/>
<Button text="Nothing"/>
</div>
}
}
```
## Views
Leptos uses a simple `view` macro to create the user interface. Its much like HTML, with the following differences:
1. Text within elements follows the rules of normal Rust strings (i.e., quotation marks or other string syntax)
```rust
view! { cx, <p>"Hello, world!"</p> }
```
2. Values can be inserted between curly braces. Reactive values
```rust
view! { cx, <p id={non_reactive_variable}>{move || value()}</p> }
```

View File

@@ -1,37 +0,0 @@
# Getting Started
> The code for this chapter can be found [here](https://github.com/gbj/leptos/tree/main/docs/book/project/ch01_getting_started).
The easiest way to get started using Leptos is to use [Trunk](https://trunkrs.dev/), as many of our [examples](https://github.com/gbj/leptos/tree/main/examples) do.
If you dont already have it installed, you can install Trunk by running
```bash
cargo install --lock trunk
```
Create a basic Rust binary project
```bash
cargo init leptos-todo
```
Add `leptos` as a dependency to your `Cargo.toml` with the `csr` featured enabled. (That stands for “client-side rendering.” Well talk more about Leptoss support for server-side rendering and hydration later.)
```toml
leptos = { version = "0.0", features = ["csr"] }
```
Youll want to set up a basic `index.html` with the following content:
```html
{{#include ../project/ch01_getting_started/index.html}}
```
Lets start with a very simple `main.rs`
```rust
{{#include ../project/ch01_getting_started/src/main.rs}}
```
Now run `trunk serve --open`. Trunk should automatically compile your app and open it in your default browser.

View File

@@ -0,0 +1,76 @@
# Interlude: Reactivity and Functions
One of our core contributors said to me recently: “I never used closures this often
until I started using Leptos.” And its true. Closures are at the heart of any Leptos
application. It sometimes looks a little silly:
```rust
// a signal holds a value, and can be updated
let (count, set_count) = create_signal(cx, 0);
// a derived signal is a function that accesses other signals
let double_count = move || count() * 2;
let count_is_odd = move || count() & 1 == 1;
let text = move || if count_is_odd() {
"odd"
} else {
"even"
};
// an effect automatically tracks the signals it depends on
// and reruns when they change
create_effect(cx, move |_| {
log!("text = {}", text());
});
view! { cx,
<p>{move || text().to_uppercase()}</p>
}
```
Closures, closures everywhere!
But why?
## Functions and UI Frameworks
Functions are at the heart of every UI framework. And this makes perfect sense. Creating a user interface is basically divided into two phases:
1. initial rendering
2. updates
In a web framework, the framework does some kind of initial rendering. Then it hands control back over to the browser. When certain events fire (like a mouse click) or asynchronous tasks finish (like an HTTP request finishing), the browser wakes the framework back up to update something. The framework runs some kind of code to update your user interface, and goes back asleep until the browser wakes it up again.
The key phrase here is “runs some kind of code.” The natural way to “run some kind of code” at an arbitrary point in time—in Rust or in any other programming language—is to call a function. And in fact every UI framework is based on rerunning some kind of function over and over:
1. virtual DOM (VDOM) frameworks like React, Yew, or Dioxus rerun a component or render function over and over, to generate a virtual DOM tree that can be reconciled with the previous result to patch the DOM
2. compiled frameworks like Angular and Svelte divide your component templates into “create” and “update” functions, rerunning the update function when they detect a change to the components state
3. in fine-grained reactive frameworks like SolidJS, Sycamore, or Leptos, _you_ define the functions that rerun
Thats what all our components are doing.
Take our typical `<SimpleCounter/>` example in its simplest form:
```rust
#[component]
pub fn SimpleCounter(cx: Scope) -> impl IntoView {
let (value, set_value) = create_signal(cx, 0);
let increment = move |_| set_value.update(|value| *value += 1);
view! { cx,
<button on:click=increment>
{value}
</button>
}
}
```
The `SimpleCounter` function itself runs once. The `value` signal is created once. The framework hands off the `increment` function to the browser as an event listener. When you click the button, the browser calls `increment`, which updates `value` via `set_value`. And that updates the single text node represented in our view by `{value}`.
Closures are key to reactivity. They provide the framework with the ability to rerun the smallest possible unit of your application in responsive to a change.
So remember two things:
1. Your component function is a setup function, not a render function: it only runs once.
2. For values in your view template to be reactive, they must be functions: either signals (which implement the `Fn` traits) or closures.

View File

@@ -1,11 +0,0 @@
# Introduction
This book is intended as an introduction to the [Leptos](https://github.com/gbj/leptos) Web framework. Together, well build a simple todo app—first as a client-side app, then as a full-stack app.
The guide doesnt assume you know anything about fine-grained reactivity or the details of modern Web frameworks. It does assume you are familiar with the Rust programming language, HTML, CSS, and the DOM and other Web APIs.
Leptos is most similar to frameworks like [Solid](https://www.solidjs.com) (JavaScript) and [Sycamore](https://sycamore-rs.netlify.app/) (Rust). There are some similarities to other frameworks like React (JavaScript), Yew (Rust), and Dioxus (Rust), so knowledge of one of those frameworks may also make it easier to understand Leptos.
You can find more detailed docs for each part of the API at [Docs.rs](https://docs.rs/leptos/latest/leptos/).
**The guide is a work in progress.**

View File

@@ -1,62 +0,0 @@
# Reactivity
## Signals
A **signal** is a piece of data that may change over time, and notifies other code when it has changed. This is the core primitive of Leptoss reactive system.
Creating a signal is very simple. You call `create_signal`, passing in the reactive scope and the default value, and receive a tuple containing a `ReadSignal` and a `WriteSignal`.
```rust
let (value, set_value) = create_signal(cx, 0);
```
> If youve used signals in Sycamore or Solid, observables in MobX or Knockout, or a similar primitive in reactive library, you probably have a pretty good idea of how signals work in Leptos. If youre familiar with React, Yew, or Dioxus, you may recognize a similar pattern to their `use_state` hooks.
### `ReadSignal<T>`
The `ReadSignal` half of this tuple allows you to get the current value of the signal. Reading that value in a reactive context automatically subscribes to any further changes. You can access the value by simply calling the `ReadSignal` as a function.
```rust
let (value, set_value) = create_signal(cx, 0);
// calling value() with return the current value of the signal,
// and automatically track changes if you're in a reactive context
assert_eq!(value(), 0);
```
> Here, a **reactive context** means anywhere within an `Effect`. Leptoss templating system is built on top of its reactive system, so if youre reading the signals value within the template, the template will automatically subscribe to the signal and update exactly the value that needs to change in the DOM.
Calling a `ReadSignal` clones the value it contains. If thats too expensive, use `ReadSignal::with()` to borrow the value and do whatever you need.
```rust
struct MySuperExpensiveStruct {
a: String,
b: StructThatsSuperExpensiveToClone
}
let (value, set_value) = create_signal(cx, MySuperExpensiveStruct::default());
// ❌ this is going to clone the `StructThatsSuperExpensiveToClone` unnecessarily!
let lowercased = move || value().a.to_lowercase();
// ✅ only use what we need
let lowercased = move || value.with(|value| value.to_lowercase());
// 🔥 aaaand there's no need to type "value" three times in a row
let lowercased = move || value.with(String::to_lowercase);
```
### `WriteSignal<T>`
The `WriteSignal` half of this tuple allows you to update the value of the signal, which will automatically notify anything thats listening to the value that something has changed. If you simply call the `WriteSignal` as a function, its value will be set to the argument you pass. If you want to mutate the value in place instead of replacing it, you can call `WriteSignal::update` instead.
```rust
// often you just want to replace the value
let (value, set_value) = create_signal(cx, 0);
set_value(1);
assert_eq!(value(), 1);
// sometimes you want to mutate something in place, like a Vec. Just call update()
let (items, set_items) = create_signal(cx, vec![0]);
set_items.update(|items: &mut Vec<i32>| items.push(1));
assert_eq!(items(), vec![1]);
```
> Under the hood, `set_value(1)` is just syntactic sugar for `set_value.update(|n| *n = 1)`.

View File

@@ -0,0 +1,101 @@
# Defining Routes
## Getting Started
Its easy to get started with the router.
First things first, make sure youve added the `leptos_router` package to your dependencies.
> Its important that the router is a separate package from `leptos` itself. This means that everything in the router can be defined in user-land code. If you want to create your own router, or use no router, youre completely free to do that!
And import the relevant types from the router, either with something like
```rust
use leptos_router::{Route, RouteProps, Router, RouterProps, Routes, RoutesProps};
```
or simply
```rust
use leptos_router::*;
```
## Providing the `<Router/>`
Routing behavior is provided by the [`<Router/>`](https://docs.rs/leptos_router/latest/leptos_router/fn.Router.html) component. This should usually be somewhere near the root of your application, the rest of the app.
> You shouldnt try to use multiple `<Router/>`s in your app. Remember that the router drives global state: if you have multiple routers, which ones decides what to do when the URL changes?
Lets start with a simple `<App/>` component using the router:
```rust
use leptos::*;
use leptos_router::*;
#[component]
pub fn App(cx: Scope) -> impl IntoView {
view! {
<Router>
<nav>
/* ... */
</nav>
<main>
/* ... */
</main>
</Router>
}
}
```
## Defining `<Routes/>`
The [`<Routes/>`](https://docs.rs/leptos_router/latest/leptos_router/fn.Routes.html) component is where you define all the routes to which a user can navigate in your application. Each possible route is defined by a [`<Route/>`](https://docs.rs/leptos_router/latest/leptos_router/fn.Route.html) component.
You should place the `<Routes/>` component at the location within your app where you want routes to be rendered. Everything outside `<Routes/>` will be present on every page, so you can leave things like a navigation bar or menu outside the `<Routes/>`.
```rust
use leptos::*;
use leptos_router::*;
#[component]
pub fn App(cx: Scope) -> impl IntoView {
view! {
<Router>
<nav>
/* ... */
</nav>
<main>
// all our routes will appear inside <main>
<Routes>
/* ... */
</Routes>
</main>
</Router>
}
}
```
Individual routes are defined by providing children to `<Routes/>` with the `<Route/>` component. `<Route/>` takes a `path` and a `view`. When the current location matches `path`, the `view` will be created and displayed.
The `path` can include
- a static path (`/users`),
- dynamic, named parameters beginning with a colon (`/:id`),
- and/or a wildcard beginning with an asterisk (`/user/*any`)
The `view` is a function that takes a `Scope` and returns a view.
```rust
<Routes>
<Route path="/" view=|cx| view! { cx, <Home/> }/>
<Route path="/users" view=|cx| view! { cx, <Users/> }/>
<Route path="/users/:id" view=|cx| view! { cx, <UserProfile/> }/>
<Route path="/*any" view=|cx| view! { cx, <NotFound/> }/>
</Routes>
```
> The router scores each route to see how good a match it is, so you can define your routes in any order.
Now if you navigate to `/` or to `/users` youll get the home page or the `<Users/>`. If you go to `/users/3` or `/blahblah` youll get a user profile or your 404 page (`<NotFound/>`). On every navigation, the router determines which `<Route/>` should be matched, and therefore what content should be displayed where the `<Routes/>` component is defined.
Simple enough?

View File

@@ -0,0 +1,170 @@
# Nested Routing
We just defined the following set of routes:
```rust
<Routes>
<Route path="/" view=|cx| view! { cx, <Home /> }/>
<Route path="/users" view=|cx| view! { cx, <Users /> }/>
<Route path="/users/:id" view=|cx| view! { cx, <UserProfile /> }/>
<Route path="/*any" view=|cx| view! { cx, <NotFound /> }/>
</Routes>
```
Theres a certain amount of duplication here: `/users` and `/users/:id`. This is fine for a small app, but you can probably already tell it wont scale well. Wouldnt it be nice if we could nest these routes?
Well... you can!
```rust
<Routes>
<Route path="/" view=|cx| view! { cx, <Home /> }/>
<Route path="/users" view=|cx| view! { cx, <Users /> }>
<Route path=":id" view=|cx| view! { cx, <UserProfile /> }/>
</Route>
<Route path="/*any" view=|cx| view! { cx, <NotFound /> }/>
</Routes>
```
But wait. Weve just subtly changed what our application does.
The next section is one of the most important in this entire routing section of the guide. Read it carefully, and feel free to ask questions if theres anything you dont understand.
# Nested Routes as Layout
Nested routes are a form of layout, not a method of route definition.
Let me put that another way: The goal of defining nested routes is not primarily to avoid repeating yourself when typing out the paths in your route definitions. It is actually to tell the router to display multiple `<Route/>`s on the page at the same time, side by side.
Lets look back at our practical example.
```rust
<Routes>
<Route path="/users" view=|cx| view! { cx, <Users /> }/>
<Route path="/users/:id" view=|cx| view! { cx, <UserProfile /> }/>
</Routes>
```
This means:
- If I go to `/users`, I get the `<Users/>` component.
- If I go to `/users/3`, I get the `<UserProfile/>` component (with the parameter `id` set to `3`; more on that later)
Lets say I use nested routes instead:
```rust
<Routes>
<Route path="/users" view=|cx| view! { cx, <Users /> }>
<Route path=":id" view=|cx| view! { cx, <UserProfile /> }/>
</Route>
</Routes>
```
This means:
- If I go to `/users/3`, the path matches two `<Route/>`s: `<Users/>` and `<UserProfile/>`.
- If I go to `/users`, the path is not matched.
I actually need to add a fallback route
```rust
<Routes>
<Route path="/users" view=|cx| view! { cx, <Users /> }>
<Route path=":id" view=|cx| view! { cx, <UserProfile /> }/>
<Route path="" view=|cx| view! { cx, <NoUser /> }/>
</Route>
</Routes>
```
Now:
- If I go to `/users/3`, the path matches `<Users/>` and `<UserProfile/>`.
- If I go to `/users`, the path matches `<Users/>` and `<NoUser/>`.
When I use nested routes, in other words, each **path** can match multiple **routes**: each URL can render the views provided by multiple `<Route/>` components, at the same time, on the same page.
This may be counter-intuitive, but its very powerful, for reasons youll hopefully see in a few minutes.
## Why Nested Routing?
Why bother with this?
Most web applications contain levels of navigation that correspond to different parts of the layout. For example, in an email app you might have a URL like `/contacts/greg`, which shows a list of contacts on the left of the screen, and contact details for Greg on the right of the screen. The contact list and the contact details should always appear on the screen at the same time. If theres no contact selected, maybe you want to show a little instructional text.
You can easily define this with nested routes
```rust
<Routes>
<Route path="/contacts" view=|cx| view! { cx, <ContactList/> }>
<Route path=":id" view=|cx| view! { cx, <ContactInfo/> }/>
<Route path="" view=|cx| view! { cx,
<p>"Select a contact to view more info."</p>
}/>
</Route>
</Routes>
```
You can go even deeper. Say you want to have tabs for each contacts address, email/phone, and your conversations with them. You can add _another_ set of nested routes inside `:id`:
```rust
<Routes>
<Route path="/contacts" view=|cx| view! { cx, <ContactList/> }>
<Route path=":id" view=|cx| view! { cx, <ContactInfo/> }>
<Route path="" view=|cx| view! { cx, <EmailAndPhone/> }/>
<Route path="address" view=|cx| view! { cx, <Address/> }/>
<Route path="messages" view=|cx| view! { cx, <Messages/> }/>
</Route>
<Route path="" view=|cx| view! { cx,
<p>"Select a contact to view more info."</p>
}/>
</Route>
</Routes>
```
> The main page of the [Remix website](https://remix.run/), a React framework from the creators of React Router, has a great visual example if you scroll down, with three levels of nested routing: Sales > Invoices > an invoice.
## `<Outlet/>`
Parent routes do not automatically render their nested routes. After all, they are just components; they dont know exactly where they should render their children, and “just stick at at the end of the parent component” is not a great answer.
Instead, you tell a parent component where to render any nested components with an `<Outlet/>` component. The `<Outlet/>` simply renders one of two things:
- if there is no nested route that has been matched, it shows nothing
- if there is a nested route that has been matched, it shows its `view`
Thats all! But its important to know and to remember, because its a common source of “Why isnt this working?” frustration. If you dont provide an `<Outlet/>`, the nested route wont be displayed.
```rust
#[component]
pub fn ContactList(cx: Scope) -> impl IntoView {
let contacts = todo!();
view! { cx,
<div style="display: flex">
// the contact list
<For each=contacts
key=|contact| contact.id
view=|cx, contact| todo!()
>
// the nested child, if any
// dont forget this!
<Outlet/>
</div>
}
}
```
## Nested Routing and Performance
All of this is nice, conceptually, but again—whats the big deal?
Performance.
In a fine-grained reactive library like Leptos, its always important to do the least amount of rendering work you can. Because were working with real DOM nodes and not diffing a virtual DOM, we want to “rerender” components as infrequently as possible. Nested routing makes this extremely easy.
Imagine my contact list example. If I navigate from Greg to Alice to Bob and back to Greg, the contact information needs to change on each navigation. But the `<ContactList/>` should never be rerendered. Not only does this save on rendering performance, it also maintains state in the UI. For example, if I have a search bar at the top of `<ContactList/>`, navigating from Greg to Alice to Bob wont clear the search.
In fact, in this case, we dont even need to rerender the `<Contact/>` component when moving between contacts. The router will just reactively update the `:id` parameter as we navigate, allowing us to make fine-grained updates. As we navigate between contacts, well update single text nodes to change the contacts name, address, and so on, without doing _any_ additional rerendering.
> This sandbox includes a couple features (like nested routing) discussed in this section and the previous one, and a couple well cover in the rest of this chapter. The router is such an integrated system that it makes sense to provide a single example, so dont be surprised if theres anything you dont understand.
<iframe src="https://codesandbox.io/p/sandbox/16-router-fy4tjv?file=%2Fsrc%2Fmain.rs&selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A3%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A3%7D%5D" width="100%" height="1000px"></iframe>

View File

@@ -0,0 +1,77 @@
# Params and Queries
Static paths are useful for distinguishing between different pages, but almost every application wants to pass data through the URL at some point.
There are two ways you can do this:
1. named route **params** like `id` in `/users/:id`
2. named route **queries** like `q` in `/search?q=Foo`
Because of the way URLs are built, you can access the query from _any_ `<Route/>` view. You can access route params from the `<Route/>` that defines them or any of its nested children.
Accessing params and queries is pretty simple with a couple of hooks:
- [`use_query`](https://docs.rs/leptos_router/latest/leptos_router/fn.use_query.html) or [`use_query_map`](https://docs.rs/leptos_router/latest/leptos_router/fn.use_query_map.html)
- [`use_params`](https://docs.rs/leptos_router/latest/leptos_router/fn.use_params.html) or [`use_params_map`](https://docs.rs/leptos_router/latest/leptos_router/fn.use_query_map.html)
Each of these comes with a typed option (`use_query` and `use_params`) and an untyped option (`use_query_map` and `use_params_map`).
The untyped versions hold a simple key-value map. To use the typed versions, derive the [`Params`](https://docs.rs/leptos_router/0.2.3/leptos_router/trait.Params.html) trait on a struct.
> `Params` is a very lightweight trait to convert a flat key-value map of strings into a struct by applying `FromStr` to each field. Because of the flat structure of route params and URL queries, its significantly less flexible than something like `serde`; it also adds much less weight to your binary.
```rust
use leptos::*;
use leptos_router::*;
#[derive(Params)]
struct ContactParams {
id: usize
}
#[derive(Params)]
struct ContactSearch {
q: String
}
```
> Note: The `Params` derive macro is located at `leptos::Params`, and the `Params` trait is at `leptos_router::Params`. If you avoid using glob imports like `use leptos::*;`, make sure youre importing the right one for the derive macro.
Now we can use them in a component. Imagine a URL that has both params and a query, like `/contacts/:id?q=Search`.
The typed versions return `Memo<Result<T>, _>`. Its a Memo so it reacts to changes in the URL. Its a `Result` because the params or query need to be parsed from the URL, and may or may not be valid.
```rust
let params = use_params::<ContactParams>(cx);
let query = use_query::<ContactSearch>(cx);
// id: || -> usize
let id = move || {
params.with(|params| {
params
.map(|params| params.id)
.unwrap_or_default()
})
};
```
The untyped versions return `Memo<ParamsMap>`. Again, its memo to react to changes in the URL. [`ParamsMap`](https://docs.rs/leptos_router/0.2.3/leptos_router/struct.ParamsMap.html) behaves a lot like any other map type, with a `.get()` method that returns `Option<&String>`.
```rust
let params = use_params::<ContactParams>(cx);
let query = use_query::<ContactSearch>(cx);
// id: || -> Option<String>
let id = move || {
params.with(|params| params.get("id").cloned())
};
```
This can get a little messy: deriving a signal that wraps an `Option<_>` or `Result<_>` can involve a couple steps. But its worth doing this for two reasons:
1. Its correct, i.e., it forces you to consider the cases, “What if the user doesnt pass a value for this query field? What if they pass an invalid value?”
2. Its performant. Specifically, when you navigate between different paths that match the same `<Route/>` with only params or the query changing, you can get fine-grained updates to different parts of your app without rerendering. For example, navigating between different contacts in our contact-list example does a targeted update to the name field (and eventually contact info) without needing to replacing or rerender the wrapping `<Contact/>`. This is what fine-grained reactivity is for.
> This is the same example from the previous section. The router is such an integrated system that it makes sense to provide a single example highlighting multiple features, even if we havent explain them all yet.
<iframe src="https://codesandbox.io/p/sandbox/16-router-fy4tjv?file=%2Fsrc%2Fmain.rs&selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A3%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A3%7D%5D" width="100%" height="1000px"></iframe>

View File

@@ -0,0 +1,21 @@
# The `<A/>` Component
Client-side navigation works perfectly fine with ordinary HTML `<a>` elements. The router adds a listener that handles every click on a `<a>` element and tries to handle it on the client side, i.e., without doing another round trip to the server to request HTML. This is what enables the snappy “single-page app” navigations youre probably familiar with from most modern web apps.
The router will bail out of handling an `<a>` click under a number of situations
- the click event has had `prevent_default()` called on it
- the <kbd>Meta</kbd>, <kbd>Alt</kbd>, <kbd>Ctrl</kbd>, or <kbd>Shift</kbd> keys were held during click
- the `<a>` has a `target` or `download` attribute, or `rel="external"`
- the link has a different origin from the current location
In other words, the router will only try to do a client-side navigation when its pretty sure it can handle it, and it will upgrade every `<a>` element to get this special behavior.
The router also provides an [`<A>`](https://docs.rs/leptos_router/latest/leptos_router/fn.A.html) component, which does two additional things:
1. Correctly resolves relative nested routes. Relative routing with ordinary `<a>` tags can be tricky. For example, if you have a route like `/post/:id`, `<A href="1">` will generate the correct relative route, but `<a href="1">` likely will not (depending on where it appears in your view.) `<A/>` resolves routes relative to the path of the nested route within which it appears.
2. Sets the `aria-current` attribute to `page` if this link is the active link (i.e., its a link to the page youre on). This is helpful for accessibility and for styling. For example, if you want to set the link a different color if its a link to the page youre currently on, you can match this attribute with a CSS selector.
> Once again, this is the same example. Check out the relative `<A/>` components, and take a look at the CSS in `index.html` to see the ARIA-based styling.
<iframe src="https://codesandbox.io/p/sandbox/16-router-fy4tjv?file=%2Fsrc%2Fmain.rs&selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A3%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A3%7D%5D" width="100%" height="1000px"></iframe>

View File

@@ -0,0 +1,23 @@
# Routing
## The Basics
Routing drives most websites. A router is the answer to the question, “Given this URL, what should appear on the page?”
A URL consists of many parts. For example, the URL `https://leptos.dev/blog/search?q=Search#results` consists of
- a _scheme_: `https`
- a _domain_: `leptos.dev`
- a **path**: `/blog/search`
- a **query** (or **search**): `?q=Search`
- a _hash_: `#results`
The Leptos Router works with the path and query (`/blog/search?q=Search`). Given this piece of the URL, what should the app render on the page?
## The Philosophy
In most cases, the path should drive what is displayed on the page. From the users perspective, for most appliations, most major changes in the state of the app should be reflected in the URL. If you copy and paste the URL and open it in another tab, you should find yourself more or less in the same place.
In this sense, the router is really at the heart of the global state management for your application. More than anything else, it drives what is displayed on the page.
The router handles most of this work for you by mapping the current location to particular components.

180
docs/book/src/testing.md Normal file
View File

@@ -0,0 +1,180 @@
# Testing Your Components
Testing user interfaces can be relatively tricky, but really important. This article
will discuss a couple principles and approaches for testing a Leptos app.
## 1. Test business logic with ordinary Rust tests
In many cases, it makes sense to pull the logic out of your components and test
it separately. For some simple components, theres no particular logic to test, but
for many its worth using a testable wrapping type and implementing the logic in
ordinary Rust `impl` blocks.
For example, instead of embedding logic in a component directly like this:
```rust
#[component]
pub fn TodoApp(cx: Scope) -> impl IntoView {
let (todos, set_todos) = create_signal(cx, vec![Todo { /* ... */ }]);
// ⚠️ this is hard to test because it's embedded in the component
let num_remaining = move || todos.with(|todos| {
todos.iter().filter(|todo| !todo.completed).sum()
});
}
```
You could pull that logic out into a separate data structure and test it:
```rust
pub struct Todos(Vec<Todo>);
impl Todos {
pub fn num_remaining(&self) -> usize {
todos.iter().filter(|todo| !todo.completed).sum()
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_remaining {
// ...
}
}
#[component]
pub fn TodoApp(cx: Scope) -> impl IntoView {
let (todos, set_todos) = create_signal(cx, Todos(vec![Todo { /* ... */ }]));
// ✅ this has a test associated with it
let num_remaining = move || todos.with(Todos::num_remaining);
}
```
In general, the less of your logic is wrapped into your components themselves, the
more idiomatic your code will feel and the easier it will be to test.
## 2. Test components with `wasm-bindgen-test`
[`wasm-bindgen-test`](https://crates.io/crates/wasm-bindgen-test) is a great utility
for integrating or end-to-end testing WebAssembly apps in a headless browser.
To use this testing utility, you need to add `wasm-bindgen-test` to your `Cargo.toml`:
```toml
[dev-dependencies]
wasm-bindgen-test = "0.3.0"
```
You should create tests in a separate `tests` directory. You can then run your tests in the browser of your choice:
```bash
wasm-pack test --firefox
```
> To see the full setup, check out the tests for the [`counter`](https://github.com/leptos-rs/leptos/tree/main/examples/counter) example.
### Writing Your Tests
Most tests will involve some combination of vanilla DOM manipulation and comparison to a `view`. For example, heres a test [for the
`counter` example](https://github.com/leptos-rs/leptos/blob/main/examples/counter/tests/mod.rs).
First, we set up the testing environment.
```rust
use wasm_bindgen_test::*;
use counter::*;
use leptos::*;
use web_sys::HtmlElement;
// tell the test runner to run tests in the browser
wasm_bindgen_test_configure!(run_in_browser);
```
Im going to create a simpler wrapper for each test case, and mount it there.
This makes it easy to encapsulate the test results.
```rust
// like marking a regular test with #[test]
#[wasm_bindgen_test]
fn clear() {
let document = leptos::document();
let test_wrapper = document.create_element("section").unwrap();
document.body().unwrap().append_child(&test_wrapper);
// start by rendering our counter and mounting it to the DOM
// note that we start at the initial value of 10
mount_to(
test_wrapper.clone().unchecked_into(),
|cx| view! { cx, <SimpleCounter initial_value=10 step=1/> },
);
```
Well use some manual DOM operations to grab the `<div>` that wraps
the whole component, as well as the `clear` button.
```rust
// now we extract the buttons by iterating over the DOM
// this would be easier if they had IDs
let div = test_wrapper.query_selector("div").unwrap().unwrap();
let clear = test_wrapper
.query_selector("button")
.unwrap()
.unwrap()
.unchecked_into::<web_sys::HtmlElement>();
```
Now we can use ordinary DOM APIs to simulate user interaction.
```rust
// now let's click the `clear` button
clear.click();
```
You can test individual DOM element attributes or text node values. Sometimes
I like to test the whole view at once. We can do this by testing the elements
`outerHTML` against our expectations.
```rust
assert_eq!(
div.outer_html(),
// here we spawn a mini reactive system to render the test case
run_scope(create_runtime(), |cx| {
// it's as if we're creating it with a value of 0, right?
let (value, set_value) = create_signal(cx, 0);
// we can remove the event listeners because they're not rendered to HTML
view! { cx,
<div>
<button>"Clear"</button>
<button>"-1"</button>
<span>"Value: " {value} "!"</span>
<button>"+1"</button>
</div>
}
// the view returned an HtmlElement<Div>, which is a smart pointer for
// a DOM element. So we can still just call .outer_html()
.outer_html()
})
);
```
That test involved us manually replicating the `view` thats inside the component.
There's actually an easier way to do this... We can just test against a `<SimpleCounter/>`
with the initial value `0`. This is where our wrapping element comes in: Ill just test
the wrappers `innerHTML` against another comparison case.
```rust
assert_eq!(test_wrapper.inner_html(), {
let comparison_wrapper = document.create_element("section").unwrap();
leptos::mount_to(
comparison_wrapper.clone().unchecked_into(),
|cx| view! { cx, <SimpleCounter initial_value=0 step=1/>},
);
comparison_wrapper.inner_html()
});
}
```
This is only a very limited introduction to testing. But I hope its useful as you begin to build applications.
> For more, see [the testing section of the `wasm-bindgen` guide](https://rustwasm.github.io/wasm-bindgen/wasm-bindgen-test/index.html#testing-on-wasm32-unknown-unknown-with-wasm-bindgen-test).

View File

@@ -0,0 +1,143 @@
# A Basic Component
That “Hello, world!” was a *very* simple example. Lets move on to something a
little more like an ordinary app.
First, lets edit the `main` function so that, instead of rendering the whole
app, it just renders an `<App/>` component. Components are the basic unit of
composition and design in most web frameworks, and Leptos is no exception.
Conceptually, they are similar to HTML elements: they represent a section of the
DOM, with self-contained, defined behavior. Unlike HTML elements, they are in
`PascalCase`, so most Leptos applications will start with something like an
`<App/>` component.
```rust
fn main() {
leptos::mount_to_body(|cx| view! { cx, <App/> })
}
```
Now lets define our `<App/>` component itself. Because its relatively simple,
Ill give you the whole thing up front, then walk through it line by line.
```rust
#[component]
fn App(cx: Scope) -> impl IntoView {
let (count, set_count) = create_signal(cx, 0);
view! { cx,
<button
on:click=move |_| {
set_count.update(|n| *n += 1);
}
>
"Click me: "
{move || count.get()}
</button>
}
}
```
## The Component Signature
```rust
#[component]
```
Like all component definitions, this begins with the [`#[component]`](https://docs.rs/leptos/latest/leptos/attr.component.html) macro. `#[component]` annotates a function so it can be
used as a component in your Leptos application. Well see some of the other features of
this macro in a couple chapters.
```rust
fn App(cx: Scope) -> impl IntoView
```
Every component is a function with the following characteristics
1. It takes a reactive [`Scope`](https://docs.rs/leptos/latest/leptos/struct.Scope.html)
as its first argument. This `Scope` is our entrypoint into the reactive system.
By convention, its usually named `cx`.
2. You can include other arguments, which will be available as component “props.”
3. Component functions return `impl IntoView`, which is an opaque type that includes
anything you could return from a Leptos `view`.
## The Component Body
The body of the component function is a set-up function that runs once, not a
render function that reruns multiple times. Youll typically use it to create a
few reactive variables, define any side effects that run in response to those values
changing, and describe the user interface.
```rust
let (count, set_count) = create_signal(cx, 0);
```
[`create_signal`](https://docs.rs/leptos/latest/leptos/fn.create_signal.html)
creates a signal, the basic unit of reactive change and state management in Leptos.
This returns a `(getter, setter)` tuple. To access the current value, youll
use `count.get()` (or, on `nightly` Rust, the shorthand `count()`). To set the
current value, youll call `set_count.set(...)` (or `set_count(...)`).
> `.get()` clones the value and `.set()` overwrites it. In many cases, its more
efficient to use `.with()` or `.update()`; check out the docs for [`ReadSignal`](https://docs.rs/leptos/latest/leptos/struct.ReadSignal.html) and [`WriteSignal`](https://docs.rs/leptos/latest/leptos/struct.WriteSignal.html) if youd like to learn more about those trade-offs at this point.
## The View
Leptos defines user interfaces using a JSX-like format via the [`view`](https://docs.rs/leptos/latest/leptos/macro.view.html) macro.
```rust
view! { cx,
<button
// define an event listener with on:
on:click=move |_| {
set_count.update(|n| *n += 1);
}
>
// text nodes are wrapped in quotation marks
"Click me: "
// blocks can include Rust code
{move || count.get()}
</button>
}
```
This should mostly be easy to understand: it looks like HTML, with a special
`on:click` to define a `click` event listener, a text node thats formatted like
a Rust string, and then...
```rust
{move || count.get()}
```
whatever that is.
People sometimes joke that they use more closures in their first Leptos application
than theyve ever used in their lives. And fair enough. Basically, passing a function
into the view tells the framework: “Hey, this is something that might change.”
When we click the button and call `set_count`, the `count` signal is updated. This
`move || count.get()` closure, whose value depends on the value of `count`, reruns,
and the framework makes a targeted update to that one specific text node, touching
nothing else in your application. This is what allows for extremely efficient updates
to the DOM.
Now, if you have Clippy on—or if you have a particularly sharp eye—you might notice
that this closure is redundant, at least if youre in `nightly` Rust. If youre using
Leptos with `nightly` Rust, signals are already functions, so the closure is unnecessary.
As a result, you can write a simpler view:
```rust
view! { cx,
<button /* ... */>
"Click me: "
// identical to {move || count.get()}
{count}
</button>
}
```
Remember—and this is *very important*—only functions are reactive. This means that
`{count}` and `{count()}` do very different things in your view. `{count}` passes
in a function, telling the framework to update the view every time `count` changes.
`{count()}` access the value of `count` once, and passes an `i32` into the view,
rendering it once, unreactively. You can see the difference in the CodeSandbox below!
> Throughout this tutorial, well use CodeSandbox to show interactive examples. To
show the browser in the sandbox, you may need to click `Add DevTools >
Other Previews > 8080.` Hover over any of the variables to show Rust-Analyzer details
and docs for whats going on. Feel free to fork the examples to play with them yourself!
<iframe src="https://codesandbox.io/p/sandbox/1-basic-component-3d74p3?file=%2Fsrc%2Fmain.rs&selection=%5B%7B%22endColumn%22%3A31%2C%22endLineNumber%22%3A19%2C%22startColumn%22%3A31%2C%22startLineNumber%22%3A19%7D%5D" width="100%" height="1000px"></iframe>

View File

@@ -0,0 +1,104 @@
# `view`: Dynamic Attributes and Classes
So far weve seen how to use the `view` macro to create event listeners and to
create dynamic text by passing a function (such as a signal) into the view.
But of course there are other things you might want to update in your user interface.
In this section, well look at how to update attributes and classes dynamically,
and well introduce the concept of a **derived signal**.
Lets start with a simple component that should be familiar: click a button to
increment a counter.
```rust
#[component]
fn App(cx: Scope) -> impl IntoView {
let (count, set_count) = create_signal(cx, 0);
view! { cx,
<button
on:click=move |_| {
set_count.update(|n| *n += 1);
}
```
So far, this is just the example from the last chapter.
## Dynamic Classes
Now lets say Id like to update the list of CSS classes on this element dynamically.
For example, lets say I want to add the class `red` when the count is odd. I can
do this using the `class:` syntax.
```rust
class:red=move || count() % 2 == 1
```
`class:` attributes take
1. the class name, following the colon (`red`)
2. a value, which can be a `bool` or a function that returns a `bool`
When the value is `true`, the class is added. When the value is `false`, the class
is removed. And if the value is a function that accesses a signal, the class will
reactively update when the signal changes.
Now every time I click the button, the text should toggle between red and black as
the number switches between even and odd.
## Dynamic Attributes
The same applies to plain attributes. Passing a plain string or primitive value to
an attribute gives it a static value. Passing a function (including a signal) to
an attribute causes it to update its value reactively. Lets add another element
to our view:
```rust
<progress
max="50"
// signals are functions, so this <=> `move || count.get()`
value=count
/>
```
Now every time we set the count, not only will the `class` of the `<button>` be
toggled, but the `value` of the `<progress>` bar will increase, which means that
our progress bar will move forward.
## Derived Signals
Lets go one layer deeper, just for fun.
You already know that we create reactive interfaces just by passing functions into
the `view`. This means that we can easily change our progress bar. For example,
suppose we want it to move twice as fast:
```rust
<progress
max="50"
value=move || count() * 2
/>
```
But imagine we want to reuse that calculation in more than one place. You can do this
using a **derived signal**: a closure that accesses a signal.
```rust
let double_count = move || count() * 2;
/* insert the rest of the view */
<progress
max="50"
// we use it once here
value=double_count
/>
<p>
"Double Count: "
// and again here
{double_count}
</p>
```
Derived signals let you create reactive computed values that can be used in multiple
places in your application with minimal overhead.
> Note: Using a derived signal like this means that the calculation runs once per
signal change per place we access `double_count`; in other words, twice. This is a
very cheap calculation, so thats fine. Well look at memos in a later chapter, which
are designed to solve this problem for expensive calculations.
<iframe src="https://codesandbox.io/p/sandbox/2-dynamic-attribute-pqyvzl?file=%2Fsrc%2Fmain.rs&selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A2%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A2%7D%5D" width="100%" height="1000px"></iframe>

View File

@@ -0,0 +1,317 @@
# Components and Props
So far, weve been building our whole application in a single component. This
is fine for really tiny examples, but in any real application youll need to
break the user interface out into multiple components, so you can break your
interface down into smaller, reusable, composable chunks.
Lets take our progress bar example. Imagine that you want two progress bars
instead of one: one that advances one tick per click, one that advances two ticks
per click.
You _could_ do this by just creating two `<progress>` elements:
```rust
let (count, set_count) = create_signal(cx, 0);
let double_count = move || count() * 2;
view! {
<progress
max="50"
value=count
/>
<progress
max="50"
value=double_count
/>
```
But of course, this doesnt scale very well. If you want to add a third progress
bar, you need to add this code another time. And if you want to edit anything
about it, you need to edit it in triplicate.
Instead, lets create a `<ProgressBar/>` component.
```rust
#[component]
fn ProgressBar(
cx: Scope
) -> impl IntoView {
view! { cx,
<progress
max="50"
// hmm... where will we get this from?
value=progress
/>
}
}
```
Theres just one problem: `progress` is not defined. Where should it come from?
When we were defining everything manually, we just used the local variable names.
Now we need some way to pass an argument into the component.
## Component Props
We do this using component properties, or “props.” If youve used another frontend
framework, this is probably a familiar idea. Basically, properties are to components
as attributes are to HTML elements: they let you pass additional information into
the component.
In Leptos, you define props by giving additional arguments to the component function.
```rust
#[component]
fn ProgressBar(
cx: Scope,
progress: ReadSignal<i32>
) -> impl IntoView {
view! { cx,
<progress
max="50"
// now this works
value=progress
/>
}
}
```
Now we can use our component in the main `<App/>` components view.
```rust
#[component]
fn App(cx: Scope) -> impl IntoView {
let (count, set_count) = create_signal(cx, 0);
view! { cx,
<button on:click=move |_| { set_count.update(|n| *n += 1); }>
"Click me"
</button>
// now we use our component!
<ProgressBar progress=count/>
}
}
```
Using a component in the view looks a lot like using an HTML element. Youll
notice that you can easily tell the difference between an element and a component
because components always have `PascalCase` names. You pass the `progress` prop
in as if it were an HTML element attribute. Simple.
> ### Important Note
> For every `Component`, Leptos generates a corresponding `ComponentProps` type. This
is what allows us to have named props, when Rust does not have named function parameters.
If youre defining a component in one module and importing it into another, make
sure you include this `ComponentProps` type:
>
> `use progress_bar::{ProgressBar, ProgressBarProps};`
### Reactive and Static Props
Youll notice that throughout this example, `progress` takes a reactive
`ReadSignal<i32>`, and not a plain `i32`. This is **very important**.
Component props have no special meaning attached to them. A component is simply
a function that runs once to set up the user interface. The only way to tell the
interface to respond to changing is to pass it a signal type. So if you have a
component property that will change over time, like our `progress`, it should
be a signal.
### `optional` Props
Right now the `max` setting is hard-coded. Lets take that as a prop too. But
lets add a catch: lets make this prop optional by annotating the particular
argument to the component function with `#[prop(optional)]`.
```rust
#[component]
fn ProgressBar(
cx: Scope,
// mark this prop optional
// you can specify it or not when you use <ProgressBar/>
#[prop(optional)]
max: u16,
progress: ReadSignal<i32>
) -> impl IntoView {
view! { cx,
<progress
max=max
value=progress
/>
}
}
```
Now, we can use `<ProgressBar max=50 value=count/>`, or we can omit `max`
to use the default value (i.e., `<ProgressBar value=count/>`). The default value
on an `optional` is its `Default::default()` value, which for a `u16` is going to
be `0`. In the case of a progress bar, a max value of `0` is not very useful.
So lets give it a particular default value instead.
### `default` props
You can specify a default value other than `Default::default()` pretty simply
with `#[prop(default = ...)`.
```rust
#[component]
fn ProgressBar(
cx: Scope,
#[prop(default = 100)]
max: u16,
progress: ReadSignal<i32>
) -> impl IntoView {
view! { cx,
<progress
max=max
value=progress
/>
}
}
```
### Generic Props
This is great. But we began with two counters, one driven by `count`, and one by
the derived signal `double_count`. Lets recreate that by using `double_count`
as the `progress` prop on another `<ProgressBar/>`.
```rust
#[component]
fn App(cx: Scope) -> impl IntoView {
let (count, set_count) = create_signal(cx, 0);
let double_count = move || count() * 2;
view! { cx,
<button on:click=move |_| { set_count.update(|n| *n += 1); }>
"Click me"
</button>
<ProgressBar progress=count/>
// add a second progress bar
<ProgressBar progress=double_count/>
}
}
```
Hm... this wont compile. It should be pretty easy to understand why: weve declared
that the `progress` prop takes `ReadSignal<i32>`, and `double_count` is not
`ReadSignal<i32>`. As rust-analyzer will tell you, its type is `|| -> i32`, i.e.,
its a closure that returns an `i32`.
There are a couple ways to handle this. One would be to say: “Well, I know that
a `ReadSignal` is a function, and I know that a closure is a function; maybe I
could just take any function?” If youre savvy, you may know that both these
implement the trait `Fn() -> i32`. So you could use a generic component:
```rust
#[component]
fn ProgressBar<F>(
cx: Scope,
#[prop(default = 100)]
max: u16,
progress: F
) -> impl IntoView
where
F: Fn() -> i32 + 'static,
{
view! { cx,
<progress
max=max
value=progress
/>
}
}
```
This is a perfectly reasonable way to write this component: `progress` now takes
any value that implements this `Fn()` trait.
> Note that generic component props _cannot_ be specified inline (as `<F: Fn() -> i32>`)
or as `progress: impl Fn() -> i32 + 'static,`, in part because theyre actually used to generate
a `struct ProgressBarProps`, and struct fields cannot be `impl` types.
### `into` Props
Theres one more way we could implement this, and it would be to use `#[prop(into)]`.
This attribute automatically calls `.into()` on the values you pass as props,
which allows you to easily pass props with different values.
In this case, its helpful to know about the
[`Signal`](https://docs.rs/leptos/latest/leptos/struct.Signal.html) type. `Signal`
is an enumerated type that represents any kind of readable reactive signal. It can
be useful when defining APIs for components youll want to reuse while passing
different sorts of signals. The [`MaybeSignal`](https://docs.rs/leptos/latest/leptos/enum.MaybeSignal.html) type is useful when you want to be able to take either a static or
reactive value.
```rust
#[component]
fn ProgressBar(
cx: Scope,
#[prop(default = 100)]
max: u16,
#[prop(into)]
progress: Signal<i32>
) -> impl IntoView
{
view! { cx,
<progress
max=max
value=progress
/>
}
}
#[component]
fn App(cx: Scope) -> impl IntoView {
let (count, set_count) = create_signal(cx, 0);
let double_count = move || count() * 2;
view! { cx,
<button on:click=move |_| { set_count.update(|n| *n += 1); }>
"Click me"
</button>
// .into() converts `ReadSignal` to `Signal`
<ProgressBar progress=count/>
// use `Signal::derive()` to wrap a derived signal
<ProgressBar progress=Signal::derive(cx, double_count)/>
}
}
```
## Documenting Components
This is one of the least essential but most important sections of this book.
Its not strictly necessary to document your components and their props. It may
be very important, depending on the size of your team and your app. But its very
easy, and bears immediate fruit.
To document a component and its props, you can simply add doc comments on the
component function, and each one of the props:
```rust
/// Shows progress toward a goal.
#[component]
fn ProgressBar(
cx: Scope,
/// The maximum value of the progress bar.
#[prop(default = 100)]
max: u16,
/// How much progress should be displayed.
#[prop(into)]
progress: Signal<i32>,
) -> impl IntoView {
/* ... */
}
```
Thats all you need to do. These behave like ordinary Rust doc comments, except
that you can document individual component props, which cant be done with Rust
function arguments.
This will automatically generate documentation for your component, its `Props`
type, and each of the fields used to add props. It can be a little hard to
understand how powerful this is until you hover over the component name or props
and see the power of the `#[component]` macro combined with rust-analyzer here.
<iframe src="https://codesandbox.io/p/sandbox/3-components-50t2e7?file=%2Fsrc%2Fmain.rs&selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A7%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A7%7D%5D" width="100%" height="1000px"></iframe>

View File

@@ -0,0 +1,88 @@
# Iteration
Whether youre listing todos, displaying a table, or showing product images,
iterating over a list of items is a common task in web applications. Reconciling
the differences between changing sets of items can also be one of the trickiest
tasks for a framework to handle well.
Leptos supports to two different patterns for iterating over items:
1. For static views: `Vec<_>`
2. For dynamic lists: `<For/>`
## Static Views with `Vec<_>`
Sometimes you need to show an item repeatedly, but the list youre drawing from
does not often change. In this case, its important to know that you can insert
any `Vec<IV> where IV: IntoView` into your view. In other words, if you can render
`T`, you can render `Vec<T>`.
```rust
let values = vec![0, 1, 2];
view! { cx,
// this will just render "012"
<p>{values.clone()}</p>
// or we can wrap them in <li>
<ul>
{values.into_iter()
.map(|n| view! { cx, <li>{n}</li>})
.collect::<Vec<_>>()}
</ul>
}
```
The fact that the _list_ is static doesnt mean the interface needs to be static.
You can render dynamic items as part of a static list.
```rust
// create a list of N signals
let counters = (1..=length).map(|idx| create_signal(cx, idx));
// each item manages a reactive view
// but the list itself will never change
let counter_buttons = counters
.map(|(count, set_count)| {
view! { cx,
<li>
<button
on:click=move |_| set_count.update(|n| *n += 1)
>
{count}
</button>
</li>
}
})
.collect::<Vec<_>>();
view! { cx,
<ul>{counter_buttons}</ul>
}
```
You _can_ render a `Fn() -> Vec<_>` reactively as well. But note that every time
it changes, this will rerender every item in the list. This is quite inefficient!
Fortunately, theres a better way.
## Dynamic Rendering with the `<For/>` Component
The [`<For/>`](https://docs.rs/leptos/latest/leptos/fn.For.html) component is a
keyed dynamic list. It takes three props:
- `each`: a function (such as a signal) that returns the items `T` to be iterated over
- `key`: a key function that takes `&T` and returns a stable, unique key or ID
- `view`: renders each `T` into a view
`key` is, well, the key. You can add, remove, and move items within the list. As
long as each items key is stable over time, the framework does not need to rerender
any of the items, unless they are new additions, and it can very efficiently add,
remove, and move items as they change. This allows for extremely efficient updates
to the list as it changes, with minimal additional work.
Creating a good `key` can be a little tricky. You generally do _not_ want to use
an index for this purpose, as it is not stable—if you remove or move items, their
indices change.
But its a great idea to do something like generating a unique ID for each row as
it is generated, and using that as an ID for the key function.
Check out the `<DynamicList/>` component below for an example.
<iframe src="https://codesandbox.io/p/sandbox/4-iteration-sglt1o?file=%2Fsrc%2Fmain.rs&selection=%5B%7B%22endColumn%22%3A6%2C%22endLineNumber%22%3A55%2C%22startColumn%22%3A5%2C%22startLineNumber%22%3A31%7D%5D" width="100%" height="1000px"></iframe>

View File

@@ -0,0 +1,107 @@
# Forms and Inputs
Forms and form inputs are an important part of interactive apps. There are two
basic patterns for interacting with inputs in Leptos, which you may recognize
if youre familiar with React, SolidJS, or a similar framework: using **controlled**
or **uncontrolled** inputs.
## Controlled Inputs
In a "controlled input," the framework controls the state of the input
element. On every `input` event, it updates a local signal that holds the current
state, which in turn updates the `value` prop of the input.
There are two important things to remember:
1. The `input` event fires on (almost) every change to the element, while the
`change` event fires (more or less) when you unfocus the input. You probably
want `on:input`, but we give you the freedom to choose.
2. The `value` *attribute* only sets the initial value of the input, i.e., it
only updates the input up to the point that you begin typing. The `value`
*property* continues updating the input after that. You usually want to set
`prop:value` for this reason.
```rust
let (name, set_name) = create_signal(cx, "Controlled".to_string());
view! { cx,
<input type="text"
on:input=move |ev| {
// event_target_value is a Leptos helper function
// it functions the same way as event.target.value
// in JavaScript, but smooths out some of the typecasting
// necessary to make this work in Rust
set_name(event_target_value(&ev));
}
// the `prop:` syntax lets you update a DOM property,
// rather than an attribute.
prop:value=name
/>
<p>"Name is: " {name}</p>
}
```
## Uncontrolled Inputs
In an "uncontrolled input," the browser controls the state of the input element.
Rather than continuously updating a signal to hold its value, we use a
[`NodeRef`](https://docs.rs/leptos/latest/leptos/struct.NodeRef.html) to access
the input once when we want to get its value.
In this example, we only notify the framework when the `<form>` fires a `submit`
event.
```rust
let (name, set_name) = create_signal(cx, "Uncontrolled".to_string());
let input_element: NodeRef<Input> = create_node_ref(cx);
```
`NodeRef` is a kind of reactive smart pointer: we can use it to access the
underlying DOM node. Its value will be set when the element is rendered.
```rust
let on_submit = move |ev: SubmitEvent| {
// stop the page from reloading!
ev.prevent_default();
// here, we'll extract the value from the input
let value = input_element()
// event handlers can only fire after the view
// is mounted to the DOM, so the `NodeRef` will be `Some`
.expect("<input> to exist")
// `NodeRef` implements `Deref` for the DOM element type
// this means we can call`HtmlInputElement::value()`
// to get the current value of the input
.value();
set_name(value);
};
```
Our `on_submit` handler will access the inputs value and use it to call `set_name`.
To access the DOM node stored in the `NodeRef`, we can simply call it as a function
(or using `.get()`). This will return `Option<web_sys::HtmlInputElement>`, but we
know it will already have been filled when we rendered the view, so its safe to
unwrap here.
We can then call `.value()` to get the value out of the input, because `NodeRef`
gives us access to a correctly-typed HTML element.
```rust
view! { cx,
<form on:submit=on_submit>
<input type="text"
value=name
node_ref=input_element
/>
<input type="submit" value="Submit"/>
</form>
<p>"Name is: " {name}</p>
}
```
The view should be pretty self-explanatory by now. Note two things:
1. Unlike in the controlled input example, we use `value` (not `prop:value`).
This is because were just setting the initial value of the input, and letting
the browser control its state. (We could use `prop:value` instead.)
2. We use `node_ref` to fill the `NodeRef`. (Older examples sometimes use `_ref`.
They are the same thing, but `node_ref` has better rust-analyzer support.)
<iframe src="https://codesandbox.io/p/sandbox/5-form-inputs-ih9m62?file=%2Fsrc%2Fmain.rs&selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A12%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A12%7D%5D" width="100%" height="1000px"></iframe>

View File

@@ -0,0 +1,285 @@
# Control Flow
In most applications, you sometimes need to make a decision: Should I render this
part of the view, or not? Should I render `<ButtonA/>` or `<WidgetB/>`? This is
**control flow**.
## A Few Tips
When thinking about how to do this with Leptos, its important to remember a few
things:
1. Rust is an expression-oriented language: control-flow expressions like
`if x() { y } else { z }` and `match x() { ... }` return their values. This
makes them very useful for declarative user interfaces.
2. For any `T` that implements `IntoView`—in other words, for any type that Leptos
knows how to render—`Option<T>` and `Result<T, impl Error>` _also_ implement
`IntoView`. And just as `Fn() -> T` renders a reactive `T`, `Fn() -> Option<T>`
and `Fn() -> Result<T, impl Error>` are reactive.
3. Rust has lots of handy helpers like [Option::map](https://doc.rust-lang.org/std/option/enum.Option.html#method.map),
[Option::and_then](https://doc.rust-lang.org/std/option/enum.Option.html#method.and_then),
[Option::ok_or](https://doc.rust-lang.org/std/option/enum.Option.html#method.ok_or),
[Result::map](https://doc.rust-lang.org/std/result/enum.Result.html#method.map),
[Result::ok](https://doc.rust-lang.org/std/result/enum.Result.html#method.ok), and
[bool::then](https://doc.rust-lang.org/std/primitive.bool.html#method.then) that
allow you to convert, in a declarative way, between a few different standard types,
all of which can be rendered. Spending time in the `Option` and `Result` docs in particular
is one of the best ways to level up your Rust game.
4. And always remember: to be reactive, values must be functions. Youll see me constantly
wrap things in a `move ||` closure, below. This is to ensure that they actually rerun
when the signal they depend on changes, keeping the UI reactive.
## So What?
To connect the dots a little: this means that you can actually implement most of
your control flow with native Rust code, without any control-flow components or
special knowledge.
For example, lets start with a simple signal and derived signal:
```rust
let (value, set_value) = create_signal(cx, 0);
let is_odd = move || value() & 1 == 1;
```
> If you dont recognize whats going on with `is_odd`, dont worry about it
> too much. Its just a simple way to test whether an integer is odd by doing a
> bitwise `AND` with `1`.
We can use these signals and ordinary Rust to build most control flow.
### `if` statements
Lets say I want to render some text if the number is odd, and some other text
if its even. Well, how about this?
```rust
view! { cx,
<p>
{move || if is_odd() {
"Odd"
} else {
"Even"
}}
</p>
}
```
An `if` expression returns its value, and a `&str` implements `IntoView`, so a
`Fn() -> &str` implements `IntoView`, so this... just works!
### `Option<T>`
Lets say we want to render some text if its odd, and nothing if its even.
```rust
let message = move || {
if is_odd() {
Some("Ding ding ding!")
} else {
None
}
};
view! { cx,
<p>{message}</p>
}
```
This works fine. We can make it a little shorter if wed like, using `bool::then()`.
```rust
let message = move || is_odd().then(|| "Ding ding ding!");
view! { cx,
<p>{message}</p>
}
```
You could even inline this if youd like, although personally I sometimes like the
better `cargo fmt` and `rust-analyzer` support I get by pulling things out of the `view`.
### `match` statements
Were still just writing ordinary Rust code, right? So you have all the power of Rusts
pattern matching at your disposal.
```rust
let message = move || {
match value() {
0 => "Zero",
1 => "One",
n if is_odd() => "Odd",
_ => "Even"
}
};
view! { cx,
<p>{message}</p>
}
```
And why not? YOLO, right?
## Preventing Over-Rendering
Not so YOLO.
Everything weve just done is basically fine. But theres one thing you should remember
and try to be careful with. Each one of the control-flow functions weve created so far
is basically a derived signal: it will rerun every time the value changes. In the examples
above, where the value switches from even to odd on every change, this is fine.
But consider the following example:
```rust
let (value, set_value) = create_signal(cx, 0);
let message = move || if value() > 5 {
"Big"
} else {
"Small"
};
view! { cx,
<p>{message}</p>
}
```
This _works_, for sure. But if you added a log, you might be surprised
```rust
let message = move || if value() > 5 {
log!("{}: rendering Big", value());
"Big"
} else {
log!("{}: rendering Small", value());
"Small"
};
```
As a user clicks a button, youd see something like this:
```
1: rendering Small
2: rendering Small
3: rendering Small
4: rendering Small
5: rendering Small
6: rendering Big
7: rendering Big
8: rendering Big
... ad infinitum
```
Every time `value` changes, it reruns the `if` statement. This makes sense, with
how reactivity works. But it has a downside. For a simple text node, rerunning
the `if` statement and rerendering isnt a big deal. But imagine it were
like this:
```rust
let message = move || if value() > 5 {
<Big/>
} else {
<Small/>
};
```
This rerenders `<Small/>` five times, then `<Big/>` infinitely. If theyre
loading resources, creating signals, or even just creating DOM nodes, this is
unnecessary work.
### `<Show/>`
The [`<Show/>`](https://docs.rs/leptos/latest/leptos/fn.Show.html) component is
the answer. You pass it a `when` condition function, a `fallback` to be shown if
the `when` function returns `false`, and children to be rendered if `when` is `true`.
```rust
let (value, set_value) = create_signal(cx, 0);
view! { cx,
<Show
when=move || value() > 5
fallback=|cx| view! { cx, <Small/> }
>
<Big/>
</Show>
}
```
`<Show/>` memoizes the `when` condition, so it only renders its `<Small/>` once,
continuing to show the same component until `value` is greater than five;
then it renders `<Big/>` once, continuing to show it indefinitely.
This is a helpful tool to avoid rerendering when using dynamic `if` expressions.
As always, there's some overhead: for a very simple node (like updating a single
text node, or updating a class or attribute), a `move || if ...` will be more
efficient. But if its at all expensive to render either branch, reach for
`<Show/>`.
## Note: Type Conversions
Theres one final thing its important to say in this section.
The `view` macro doesnt return the most-generic wrapping type
[`View`](https://docs.rs/leptos/latest/leptos/enum.View.html).
Instead, it returns things with types like `Fragment` or `HtmlElement<Input>`. This
can be a little annoying if youre returning different HTML elements from
different branches of a conditional:
```rust,compile_error
view! { cx,
<main>
{move || match is_odd() {
true if value() == 1 => {
// returns HtmlElement<Pre>
view! { cx, <pre>"One"</pre> }
},
false if value() == 2 => {
// returns HtmlElement<P>
view! { cx, <p>"Two"</p> }
}
// returns HtmlElement<Textarea>
_ => view! { cx, <textarea>{value()}</textarea> }
}}
</main>
}
```
This strong typing is actually very powerful, because
[`HtmlElement`](https://docs.rs/leptos/0.1.3/leptos/struct.HtmlElement.html) is,
among other things, a smart pointer: each `HtmlElement<T>` type implements
`Deref` for the appropriate underlying `web_sys` type. In other words, in the browser
your `view` returns real DOM elements, and you can access native DOM methods on
them.
But it can be a little annoying in conditional logic like this, because you cant
return different types from different branches of a condition in Rust. There are two ways
to get yourself out of this situation:
1. If you have multiple `HtmlElement` types, convert them to `HtmlElement<AnyElement>`
with [`.into_any()`](https://docs.rs/leptos/latest/leptos/struct.HtmlElement.html#method.into_any)
2. If you have a variety of view types that are not all `HtmlElement`, convert them to
`View`s with [`.into_view(cx)`](https://docs.rs/leptos/latest/leptos/trait.IntoView.html#tymethod.into_view).
Heres the same example, with the conversion added:
```rust,compile_error
view! { cx,
<main>
{move || match is_odd() {
true if value() == 1 => {
// returns HtmlElement<Pre>
view! { cx, <pre>"One"</pre> }.into_any()
},
false if value() == 2 => {
// returns HtmlElement<P>
view! { cx, <p>"Two"</p> }.into_any()
}
// returns HtmlElement<Textarea>
_ => view! { cx, <textarea>{value()}</textarea> }.into_any()
}}
</main>
}
```
<iframe src="https://codesandbox.io/p/sandbox/6-control-flow-in-view-zttwfx?file=%2Fsrc%2Fmain.rs&selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A2%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A2%7D%5D" width="100%" height="1000px"></iframe>

View File

@@ -0,0 +1,113 @@
# Error Handling
[In the last chapter](./06_control_flow.md), we saw that you can render `Option<T>`:
in the `None` case, it will render nothing, and in the `T` case, it will render `T`
(that is, if `T` implements `IntoView`). You can actually do something very similar
with a `Result<T, E>`. In the `Err(_)` case, it will render nothing. In the `Ok(T)`
case, it will render the `T`.
Lets start with a simple component to capture a number input.
```rust
#[component]
fn NumericInput(cx: Scope) -> impl IntoView {
let (value, set_value) = create_signal(cx, Ok(0));
// when input changes, try to parse a number from the input
let on_input = move |ev| set_value(event_target_value(&ev).parse::<i32>());
view! { cx,
<label>
"Type a number (or not!)"
<input type="number" on:input=on_input/>
<p>
"You entered "
<strong>{value}</strong>
</p>
</label>
}
}
```
Every time you change the input, `on_input` will attempt to parse its value into a 32-bit
integer (`i32`), and store it in our `value` signal, which is a `Result<i32, _>`. If you
type the number `42`, the UI will display
```
You entered 42
```
But if you type the string`foo`, it will display
```
You entered
```
This is not great. It saves us using `.unwrap_or_default()` or something, but it would be
much nicer if we could catch the error and do something with it.
You can do that, with the [`<ErrorBoundary/>`](https://docs.rs/leptos/latest/leptos/fn.ErrorBoundary.html)
component.
## `<ErrorBoundary/>`
An `<ErrorBoundary/>` is a little like the `<Show/>` component we saw in the last chapter.
If everythings okay—which is to say, if everything is `Ok(_)`—it renders its children.
But if theres an `Err(_)` rendered among those children, it will trigger the
`<ErrorBoundary/>`s `fallback`.
Lets add an `<ErrorBoundary/>` to this example.
```rust
#[component]
fn NumericInput(cx: Scope) -> impl IntoView {
let (value, set_value) = create_signal(cx, Ok(0));
let on_input = move |ev| set_value(event_target_value(&ev).parse::<i32>());
view! { cx,
<h1>"Error Handling"</h1>
<label>
"Type a number (or something that's not a number!)"
<input type="number" on:input=on_input/>
<ErrorBoundary
// the fallback receives a signal containing current errors
fallback=|cx, errors| view! { cx,
<div class="error">
<p>"Not a number! Errors: "</p>
// we can render a list of errors as strings, if we'd like
<ul>
{move || errors.get()
.into_iter()
.map(|(_, e)| view! { cx, <li>{e.to_string()}</li>})
.collect::<Vec<_>>()
}
</ul>
</div>
}
>
<p>"You entered " <strong>{value}</strong></p>
</ErrorBoundary>
</label>
}
}
```
Now, if you type `42`, `value` is `Ok(42)` and youll see
```
You entered 42
```
If you type `foo`, value is `Err(_)` and the `fallback` will render. Weve chosen to render
the list of errors as a `String`, so youll see something like
```
Not a number! Errors:
- cannot parse integer from empty string
```
If you fix the error, the error message will disappear and the content youre wrapping in
an `<ErrorBoundary/>` will appear again.
<iframe src="https://codesandbox.io/p/sandbox/7-error-handling-and-error-boundaries-sroncx?file=%2Fsrc%2Fmain.rs&selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A2%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A2%7D%5D" width="100%" height="1000px"></iframe>

View File

@@ -0,0 +1,288 @@
# Parent-Child Communication
You can think of your application as a nested tree of components. Each component
handles its own local state and manages a section of the user interface, so
components tend to be relatively self-contained.
Sometimes, though, youll want to communicate between a parent component and its
child. For example, imagine youve defined a `<FancyButton/>` component that adds
some styling, logging, or something else to a `<button/>`. You want to use a
`<FancyButton/>` in your `<App/>` component. But how can you communicate between
the two?
Its easy to communicate state from a parent component to a child component. We
covered some of this in the material on [components and props](./03_components.md).
Basically if you want the parent to communicate to the child, you can pass a
[`ReadSignal`](https://docs.rs/leptos/latest/leptos/struct.ReadSignal.html), a
[`Signal`](https://docs.rs/leptos/latest/leptos/struct.Signal.html), or even a
[`MaybeSignal`](https://docs.rs/leptos/latest/leptos/struct.MaybeSignal.html) as a prop.
But what about the other direction? How can a child send notifications about events
or state changes back up to the parent?
There are four basic patterns of parent-child communication in Leptos.
## 1. Pass a [`WriteSignal`](https://docs.rs/leptos/latest/leptos/struct.WriteSignal.html)
One approach is simply to pass a `WriteSignal` from the parent down to the child, and update
it in the child. This lets you manipulate the state of the parent from the child.
```rust
#[component]
pub fn App(cx: Scope) -> impl IntoView {
let (toggled, set_toggled) = create_signal(cx, false);
view! { cx,
<p>"Toggled? " {toggled}</p>
<ButtonA setter=set_toggled/>
}
}
#[component]
pub fn ButtonA(cx: Scope, setter: WriteSignal<bool>) -> impl IntoView {
view! { cx,
<button
on:click=move |_| setter.update(|value| *value = !*value)
>
"Toggle"
</button>
}
}
```
This pattern is simple, but you should be careful with it: passing around a `WriteSignal`
can make it hard to reason about your code. In this example, its pretty clear when you
read `<App/>` that you are handing off the ability to mutate `toggled`, but its not at
all clear when or how it will change. In this small, local example its easy to understand,
but if you find yourself passing around `WriteSignal`s like this throughout your code,
you should really consider whether this is making it too easy to write spaghetti code.
## 2. Use a Callback
Another approach would be to pass a callback to the child: say, `on_click`.
```rust
#[component]
pub fn App(cx: Scope) -> impl IntoView {
let (toggled, set_toggled) = create_signal(cx, false);
view! { cx,
<p>"Toggled? " {toggled}</p>
<ButtonB on_click=move |_| set_toggled.update(|value| *value = !*value)/>
}
}
#[component]
pub fn ButtonB<F>(
cx: Scope,
on_click: F,
) -> impl IntoView
where
F: Fn(MouseEvent) + 'static,
{
view! { cx,
<button on:click=on_click>
"Toggle"
</button>
}
}
```
Youll notice that whereas `<ButtonA/>` was given a `WriteSignal` and decided how to mutate it,
`<ButtonB/>` simply fires an event: the mutation happens back in `<App/>`. This has the advantage
of keeping local state local, preventing the problem of spaghetti mutation. But it also means
the logic to mutate that signal needs to exist up in `<App/>`, not down in `<ButtonB/>`. These
are real trade-offs, not a simple right-or-wrong choice.
> Note the way we declare the generic type `F` here for the callback. If youre
> confused, look back at the [generic props](./03_components.html#generic-props) section
> of the chapter on components.
## 3. Use an Event Listener
You can actually write Option 2 in a slightly different way. If the callback maps directly onto
a native DOM event, you can add an `on:` listener directly to the place you use the component
in your `view` macro in `<App/>`.
```rust
#[component]
pub fn App(cx: Scope) -> impl IntoView {
let (toggled, set_toggled) = create_signal(cx, false);
view! { cx,
<p>"Toggled? " {toggled}</p>
// note the on:click instead of on_click
// this is the same syntax as an HTML element event listener
<ButtonC on:click=move |_| set_toggled.update(|value| *value = !*value)/>
}
}
#[component]
pub fn ButtonC<F>(cx: Scope) -> impl IntoView {
view! { cx,
<button>"Toggle"</button>
}
}
```
This lets you write way less code in `<ButtonC/>` than you did for `<ButtonB/>`,
and still gives a correctly-typed event to the listener. This works by adding an
`on:` event listener to each element that `<ButtonC/>` returns: in this case, just
the one `<button>`.
Of course, this only works for actual DOM events that youre passing directly through
to the elements youre rendering in the component. For more complex logic that
doesnt map directly onto an element (say you create `<ValidatedForm/>` and want an
`on_valid_form_submit` callback) you should use Option 2.
## 4. Providing a Context
This version is actually a variant on Option 1. Say you have a deeply-nested component
tree:
```rust
#[component]
pub fn App(cx: Scope) -> impl IntoView {
let (toggled, set_toggled) = create_signal(cx, false);
view! { cx,
<p>"Toggled? " {toggled}</p>
<Layout/>
}
}
#[component]
pub fn Layout(cx: Scope) -> impl IntoView {
view! { cx,
<header>
<h1>"My Page"</h1>
</header>
<main>
<Content/>
</main>
}
}
#[component]
pub fn Content(cx: Scope) -> impl IntoView {
view! { cx,
<div class="content">
<ButtonD/>
</div>
}
}
#[component]
pub fn ButtonD<F>(cx: Scope) -> impl IntoView {
todo!()
}
```
Now `<ButtonD/>` is no longer a direct child of `<App/>`, so you cant simply
pass your `WriteSignal` to its props. You could do whats sometimes called
“prop drilling,” adding a prop to each layer between the two:
```rust
#[component]
pub fn App(cx: Scope) -> impl IntoView {
let (toggled, set_toggled) = create_signal(cx, false);
view! { cx,
<p>"Toggled? " {toggled}</p>
<Layout set_toggled/>
}
}
#[component]
pub fn Layout(cx: Scope, set_toggled: WriteSignal<bool>) -> impl IntoView {
view! { cx,
<header>
<h1>"My Page"</h1>
</header>
<main>
<Content set_toggled/>
</main>
}
}
#[component]
pub fn Content(cx: Scope, set_toggled: WriteSignal<bool>) -> impl IntoView {
view! { cx,
<div class="content">
<ButtonD set_toggled/>
</div>
}
}
#[component]
pub fn ButtonD<F>(cx: Scope, set_toggled: WriteSignal<bool>) -> impl IntoView {
todo!()
}
```
This is a mess. `<Layout/>` and `<Content/>` dont need `set_toggled`; they just
pass it through to `<ButtonD/>`. But I need to declare the prop in triplicate.
This is not only annoying but hard to maintain: imagine we add a “half-toggled”
option and the type of `set_toggled` needs to change to an `enum`. We have to change
it in three places!
Isnt there some way to skip levels?
There is!
### The Context API
You can provide data that skips levels by using [`provide_context`](https://docs.rs/leptos/latest/leptos/fn.provide_context.html)
and [`use_context`](https://docs.rs/leptos/latest/leptos/fn.use_context.html). Contexts are identified
by the type of the data you provide (in this example, `WriteSignal<bool>`), and they exist in a top-down
tree that follows the contours of your UI tree. In this example, we can use context to skip the
unnecessary prop drilling.
```rust
#[component]
pub fn App(cx: Scope) -> impl IntoView {
let (toggled, set_toggled) = create_signal(cx, false);
// share `set_toggled` with all children of this component
provide_context(cx, set_toggled);
view! { cx,
<p>"Toggled? " {toggled}</p>
<Layout/>
}
}
// <Layout/> and <Content/> omitted
#[component]
pub fn ButtonD(cx: Scope) -> impl IntoView {
// use_context searches up the context tree, hoping to
// find a `WriteSignal<bool>`
// in this case, I .expect() because I know I provided it
let setter = use_context::<WriteSignal<bool>>(cx)
.expect("to have found the setter provided");
view! { cx,
<button
on:click=move |_| setter.update(|value| *value = !*value)
>
"Toggle"
</button>
}
}
```
The same caveats apply to this as to `<ButtonA/>`: passing a `WriteSignal`
around should be done with caution, as it allows you to mutate state from
arbitrary parts of your code. But when done carefully, this can be one of
the most effective techniques for global state management in Leptos: simply
provide the state at the highest level youll need it, and use it wherever
you need it lower down.
Note that there are no performance downsides to this approach. Because you
are passing a fine-grained reactive signal, _nothing happens_ in the intervening
components (`<Layout/>` and `<Content/>`) when you update it. You are communicating
directly between `<ButtonD/>` and `<App/>`. In fact—and this is the power of
fine-grained reactivity—you are communicating directly between a button click
in `<ButtonD/>` and a single text node in `<App/>`. Its as if the components
themselves dont exist at all. And, well... at runtime, they dont. Its just
signals and effects, all the way down.
<iframe src="https://codesandbox.io/p/sandbox/8-parent-child-communication-84we8m?file=%2Fsrc%2Fmain.rs&selection=%5B%7B%22endColumn%22%3A1%2C%22endLineNumber%22%3A3%2C%22startColumn%22%3A1%2C%22startLineNumber%22%3A3%7D%5D" width="100%" height="1000px"></iframe>

View File

@@ -0,0 +1,126 @@
# Component Children
Its pretty common to want to pass children into a component, just as you can pass
children into an HTML element. For example, imagine I have a `<FancyForm/>` component
that enhances an HTML `<form>`. I need some way to pass all its inputs.
```rust
view! { cx,
<Form>
<fieldset>
<label>
"Some Input"
<input type="text" name="something"/>
</label>
</fieldset>
<button>"Submit"</button>
</Form>
}
```
How can you do this in Leptos? There are basically two ways to pass components to
other components:
1. **render props**: properties that are functions that return a view
2. the **`children`** prop: a special component property that includes anything
you pass as a child to the component.
In fact, youve already seen these both in action in the [`<Show/>`](/view/06_control_flow.html#show) component:
```rust
view! { cx,
<Show
// `when` is a normal prop
when=move || value() > 5
// `fallback` is a "render prop": a function that returns a view
fallback=|cx| view! { cx, <Small/> }
>
// `<Big/>` (and anything else here)
// will be given to the `children` prop
<Big/>
</Show>
}
```
Lets define a component that takes some children and a render prop.
```rust
#[component]
pub fn TakesChildren<F, IV>(
cx: Scope,
/// Takes a function (type F) that returns anything that can be
/// converted into a View (type IV)
render_prop: F,
/// `children` takes the `Children` type
children: Children,
) -> impl IntoView
where
F: Fn() -> IV,
IV: IntoView,
{
view! { cx,
<h2>"Render Prop"</h2>
{render_prop()}
<h2>"Children"</h2>
{children(cx)}
}
}
```
`render_prop` and `children` are both functions, so we can call them to generate
the appropriate views. `children`, in particular, is an alias for
`Box<dyn FnOnce(Scope) -> Fragment>`. (Aren't you glad we named it `Children` instead?)
> If you need a `Fn` or `FnMut` here because you need to call `children` more than once,
> we also provide `ChildrenFn` and `ChildrenMut` aliases.
We can use the component like this:
```rust
view! { cx,
<TakesChildren render_prop=|| view! { cx, <p>"Hi, there!"</p> }>
// these get passed to `children`
"Some text"
<span>"A span"</span>
</TakesChildren>
}
```
## Manipulating Children
The [`Fragment`](https://docs.rs/leptos/latest/leptos/struct.Fragment.html) type is
basically a way of wrapping a `Vec<View>`. You can insert it anywhere into your view.
But you can also access those inner views directly to manipulate them. For example, heres
a component that takes its children and turns them into an unordered list.
```rust
#[component]
pub fn WrapsChildren(cx: Scope, children: Children) -> impl IntoView {
// Fragment has `nodes` field that contains a Vec<View>
let children = children(cx)
.nodes
.into_iter()
.map(|child| view! { cx, <li>{child}</li> })
.collect::<Vec<_>>();
view! { cx,
<ul>{children}</ul>
}
}
```
Calling it like this will create a list:
```rust
view! { cx,
<WrappedChildren>
"A"
"B"
"C"
</WrappedChildren>
}
```
<iframe src="https://codesandbox.io/p/sandbox/9-component-children-2wrdfd?file=%2Fsrc%2Fmain.rs&selection=%5B%7B%22endColumn%22%3A12%2C%22endLineNumber%22%3A19%2C%22startColumn%22%3A12%2C%22startLineNumber%22%3A19%7D%5D" width="100%" height="1000px"></iframe>

View File

@@ -0,0 +1,5 @@
# Building User Interfaces
This first section will introduce you to the basic tools you need to build a reactive
user interface using Leptos. By the end of this section, you should be able to
build a simple, synchronous application that is rendered in the browser.

BIN
docs/logos/Leptos_logo_RGB.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

64
docs/logos/Leptos_logo_RGB.svg Executable file
View File

@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 27.1.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 437.4294 209.6185" style="enable-background:new 0 0 437.4294 209.6185;" xml:space="preserve">
<path style="fill:none;" d="M130.0327,79.3931c-11.4854-0.23-22.52,9.3486-24.5034,21.0117l49.1157,0.0293
c-2.1729-10.418-11.1821-21.0449-24.1987-21.0449C130.3081,79.3892,130.1714,79.3907,130.0327,79.3931z"/>
<path style="fill:#181139;" d="M95.1109,128.1089H58.6797V65.6861c0-1.5234-0.8169-2.4331-2.1855-2.4331h-3.1187
c-1.3159,0-2.2349,1.0005-2.2349,2.4331v67.4297c0,1.4521,0.8145,2.2852,2.2349,2.2852h41.7353c1.4844,0,2.4819-0.9375,2.4819-2.333
v-2.7744C97.5928,128.9253,96.6651,128.1089,95.1109,128.1089z"/>
<path style="fill:#181139;" d="M146.4561,77.1739c-4.8252-3.001-10.3037-4.5249-16.2837-4.5288c-0.0068,0-0.0137,0-0.0205,0
c-5.7349,0-11.1377,1.4639-16.0566,4.3511c-4.916,2.8853-8.8721,6.8364-11.7593,11.7456
c-2.8975,4.9248-4.3687,10.332-4.3721,16.0713c-0.0034,5.7188,1.4966,11.0654,4.4565,15.8887
c2.9893,4.9209,6.8789,8.7334,11.8887,11.6514c4.8657,2.8633,10.2397,4.3174,15.9717,4.3203c0.0073,0,0.0146,0,0.022,0
c8.123,0,14.7441-2.5869,21.4683-8.3906c0.5493-0.4805,0.8516-1.1201,0.8516-1.8008c0.001-0.6074-0.1743-1.1035-0.5205-1.4756
l-1.3569-1.8428l-0.0732-0.0859c-0.2637-0.2637-0.6929-0.6152-1.3716-0.6152c-0.6421,0-1.2549,0.2217-1.7124,0.6143
c-1.9346,1.585-3.5459,2.8008-4.7969,3.6182c-1.7979,1.208-5.8218,3.2314-12.5986,3.2314c-0.0073,0-0.0142,0-0.021,0
c-0.1357,0.0029-0.269,0.0039-0.4043,0.0039c-12.2642,0-23.4736-10.3262-24.5088-22.4814l53.0127,0.0322c0.0015,0,0.0024,0,0.0034,0
c2.2373,0,3.4697-1.1621,3.4712-3.2715c0.0034-5.2588-1.3574-10.3945-4.0464-15.2705
C155.0015,84.0953,151.2188,80.1363,146.4561,77.1739z M154.6451,100.4341l-49.1157-0.0293
c1.9834-11.6631,13.0181-21.2417,24.5034-21.0117c0.1387-0.0024,0.2754-0.0039,0.4136-0.0039
C143.4629,79.3892,152.4722,90.0162,154.6451,100.4341z"/>
<path style="fill:#181139;" d="M204.0386,136.6382c5.7319,0,11.1069-1.4502,15.9746-4.3115
c4.938-2.9014,8.75-6.7129,11.6533-11.6533c2.8608-4.8672,4.311-10.2578,4.311-16.0244c0-5.7324-1.4502-11.1064-4.311-15.9746
c-2.9019-4.9385-6.7134-8.75-11.6533-11.6533c-4.8687-2.8618-10.2437-4.3125-15.9746-4.3125
c-9.938,0-19.2021,4.7583-24.3516,12.3174v-9.438c0-0.5946-0.1465-1.0788-0.411-1.4511c-0.3815-0.5369-1.0157-0.834-1.8727-0.834
h-2.6738c-1.4521,0-2.2852,0.833-2.2852,2.2852v5.6964v46.4791v23.9676c0,1.2568,0.7808,2.0371,2.0371,2.0371h3.3667
c0.9209,0,1.6421-0.6992,1.6421-1.5908v-17.098v-10.984C185.0884,131.8892,194.2749,136.6382,204.0386,136.6382z M186.6358,122.5591
c-4.9346-4.9346-7.6831-11.4932-7.542-18.0254c-0.1367-6.3506,2.5439-12.751,7.3545-17.5605
c4.8521-4.8521,11.3037-7.5547,17.7383-7.417c4.3691,0,8.4863,1.1465,12.2314,3.4043c3.7344,2.2979,6.7456,5.4053,8.9492,9.2354
c2.1699,3.9072,3.2695,8.0967,3.2695,12.4697c0.1396,6.4619-2.5967,12.9844-7.5083,17.8955
c-4.7617,4.7617-11.0469,7.3857-17.2544,7.2803C197.6856,129.9712,191.396,127.3208,186.6358,122.5591z"/>
<path style="fill:#181139;" d="M241.8955,80.3975h7.5669v42.0259c0,6.8174,4.5674,12.1309,11.0825,12.9189
c0.6836,0.1055,1.8379,0.1572,3.5303,0.1572c2.0078,0,3.0273-0.3535,3.0273-2.2842v-2.377c0-1.7891-1.334-2.0371-2.7568-2.0371
c0,0-0.001,0-0.002,0l-1.7871-0.0488c-2.0117-0.0439-3.4883-0.7627-4.3896-2.1367c-0.9697-1.4805-1.4619-3.1738-1.4619-5.0352
V80.3975h10.0928c1.3076,0,2.2852-1.3628,2.2852-2.5815v-1.9312c0-1.3999-0.8359-2.2354-2.2354-2.2354h-10.1426V60.6861
c0-1.4619-0.7969-2.4829-1.9375-2.4829c-0.1865,0-0.4121,0-0.6392,0.0884l-2.6489,0.6865
c-1.2109,0.3682-2.0171,0.9263-2.0171,2.4507v12.2207h-7.5669c-1.4185,0-2.335,0.897-2.335,2.2852v1.8813
C239.5606,79.2393,240.6079,80.3975,241.8955,80.3975z"/>
<path style="fill:#181139;" d="M379.1182,106.2691c-4.0488-2.9219-8.8545-5.0293-14.291-6.2646
c-6.5049-1.3975-13.4473-5.2129-13.3203-10.3066c0-7.5225,6.6367-10.1914,12.3203-10.1914c5.3574,0,10.2207,3.002,13.001,8.0146
c0.6729,1.2861,1.4785,1.9375,2.3955,1.9375c0.3311,0,0.7061-0.1113,0.9922-0.2832l2.2021-1.1523
c0.5947-0.3408,0.9229-0.9414,0.9229-1.6924c0-0.5205-0.0908-0.9541-0.2617-1.292c-3.6367-8.2466-10.0967-12.4282-19.2021-12.4282
c-11.7305,0-19.6123,6.9263-19.6123,17.2349c0,4.3125,1.8438,7.9746,5.4756,10.8809c3.4482,2.7979,7.9121,4.8623,13.2705,6.1377
c4.5859,1.085,8.3193,2.5654,11.0977,4.4023c1.4159,0.9354,2.4412,2.0535,3.106,3.3672c0.6053,1.1962,0.9135,2.5535,0.9135,4.1005
c0.0742,2.3857-0.79,4.5176-2.5684,6.3389c-3.1445,3.2178-8.4053,4.6689-12.0205,4.6689c-0.0361,0-0.0723,0-0.1074,0
c-3.4268,0-6.4893-0.8438-9.1035-2.5068c-2.5918-1.6484-4.2363-3.8076-5.0293-6.6064c-0.3203-1.0996-0.751-2.1738-2.1553-2.1738
c-0.0742,0-0.2109,0.0146-0.4062,0.0449c-0.1133,0.0166-0.2559,0.0381-0.5088,0.0742l-1.8818,0.4463l-0.1045,0.0332
c-1.0244,0.4082-1.6113,1.1846-1.6113,2.1309c0,0.2285,0.0625,0.6592,0.2178,1.1094c1.9707,8.5801,10.2432,14.3447,20.5732,14.3447
c0.125,0.002,0.249,0.002,0.374,0.002c6.5947,0,12.6748-2.3193,16.7275-6.3945c3.1895-3.208,4.8311-7.2363,4.748-11.6357
c0-2.8187-0.6185-5.3109-1.8062-7.481C382.4437,109.2624,381.0062,107.631,379.1182,106.2691z"/>
<path style="fill:#EF3939;" d="M348.9043,45.7325c0-6.3157-3.2826-11.8699-8.2238-15.0756
c-2.811-1.8237-6.1537-2.8947-9.7469-2.8947c-9.9092,0-17.9707,8.0615-17.9707,17.9702c0,4.7659,1.8775,9.0925,4.9157,12.3123
c-3.6619,4.3709-6.6334,9.3336-8.7663,14.7186c-1.5873-0.2422-3.2123-0.3683-4.8662-0.3683
c-17.7158,0-32.1289,14.4131-32.1289,32.1289c0,14.6854,9.9077,27.0922,23.3869,30.9101
c-6.7762,17.3461-23.6572,29.6719-43.3742,29.6719c-16.8195,0-31.583-8.9662-39.7656-22.369
c-2.4778,0.5446-5.0429,0.8519-7.6721,0.9023c9.0226,16.99,26.8969,28.5917,47.4377,28.5917
c23.2646,0,43.1121-14.8788,50.5461-35.6179c0.5204,0.0251,1.0435,0.0398,1.5701,0.0398c17.7158,0,32.1289-14.4131,32.1289-32.1289
c0-13.557-8.4446-25.1712-20.3465-29.8811c1.9001-4.5678,4.5115-8.7646,7.6888-12.4641c0.9996,0.4404,2.0479,0.785,3.1324,1.0384
c1.3144,0.3071,2.6773,0.486,4.0839,0.486C340.8428,63.7032,348.9043,55.6416,348.9043,45.7325z M304.2461,129.5279
c-13.7871,0-25.0039-11.2168-25.0039-25.0039s11.2168-25.0039,25.0039-25.0039S329.25,90.7369,329.25,104.524
S318.0332,129.5279,304.2461,129.5279z M330.9336,34.8872c0.645,0,1.2737,0.0671,1.8881,0.1755
c5.0818,0.8974,8.9576,5.3347,8.9576,10.6697c0,5.9805-4.8652,10.8457-10.8457,10.8457s-10.8457-4.8652-10.8457-10.8457
c0-1.3967,0.2746-2.7282,0.7576-3.9555C322.4306,37.7496,326.35,34.8872,330.9336,34.8872z"/>
</svg>

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 27.1.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 437.4294 209.6185" style="enable-background:new 0 0 437.4294 209.6185;" xml:space="preserve">
<path d="M95.1109,128.1089H58.6797V65.6861c0-1.5234-0.8169-2.4331-2.1855-2.4331h-3.1187c-1.3159,0-2.2349,1.0005-2.2349,2.4331
v67.4297c0,1.4521,0.8145,2.2852,2.2349,2.2852h41.7353c1.4844,0,2.4819-0.9375,2.4819-2.333v-2.7744
C97.5928,128.9253,96.6651,128.1089,95.1109,128.1089z"/>
<path d="M146.4561,77.1739c-4.8252-3.001-10.3037-4.5249-16.2837-4.5288c-0.0068,0-0.0137,0-0.0205,0
c-5.7349,0-11.1377,1.4639-16.0566,4.3511c-4.916,2.8853-8.8721,6.8364-11.7593,11.7456
c-2.8975,4.9248-4.3687,10.332-4.3721,16.0713c-0.0034,5.7188,1.4966,11.0654,4.4565,15.8887
c2.9893,4.9209,6.8789,8.7334,11.8887,11.6514c4.8657,2.8633,10.2397,4.3174,15.9717,4.3203c0.0073,0,0.0146,0,0.022,0
c8.123,0,14.7441-2.5869,21.4683-8.3906c0.5493-0.4805,0.8516-1.1201,0.8516-1.8008c0.001-0.6074-0.1743-1.1035-0.5205-1.4756
l-1.3569-1.8428l-0.0732-0.0859c-0.2637-0.2637-0.6929-0.6152-1.3716-0.6152c-0.6421,0-1.2549,0.2217-1.7124,0.6143
c-1.9346,1.585-3.5459,2.8008-4.7969,3.6182c-1.7979,1.208-5.8218,3.2314-12.5986,3.2314c-0.0073,0-0.0142,0-0.021,0
c-0.1357,0.0029-0.269,0.0039-0.4043,0.0039c-12.2642,0-23.4736-10.3262-24.5088-22.4814l53.0127,0.0322c0.0015,0,0.0024,0,0.0034,0
c2.2373,0,3.4697-1.1621,3.4712-3.2715c0.0034-5.2588-1.3574-10.3945-4.0464-15.2705
C155.0015,84.0953,151.2188,80.1363,146.4561,77.1739z M154.6451,100.4341l-49.1157-0.0293
c1.9834-11.6631,13.0181-21.2417,24.5034-21.0117c0.1387-0.0024,0.2754-0.0039,0.4136-0.0039
C143.4629,79.3892,152.4722,90.0162,154.6451,100.4341z"/>
<path d="M204.0386,136.6382c5.7319,0,11.1069-1.4502,15.9746-4.3115c4.938-2.9014,8.75-6.7129,11.6533-11.6533
c2.8608-4.8672,4.311-10.2578,4.311-16.0244c0-5.7324-1.4502-11.1064-4.311-15.9746c-2.9019-4.9385-6.7134-8.75-11.6533-11.6533
c-4.8687-2.8618-10.2437-4.3125-15.9746-4.3125c-9.938,0-19.2021,4.7583-24.3516,12.3174v-9.438
c0-0.5946-0.1465-1.0788-0.411-1.4511c-0.3815-0.5369-1.0157-0.834-1.8727-0.834h-2.6738c-1.4521,0-2.2852,0.833-2.2852,2.2852
v5.6964v46.4791v23.9676c0,1.2568,0.7808,2.0371,2.0371,2.0371h3.3667c0.9209,0,1.6421-0.6992,1.6421-1.5908v-17.098v-10.984
C185.0884,131.8892,194.2749,136.6382,204.0386,136.6382z M186.6358,122.5591c-4.9346-4.9346-7.6831-11.4932-7.542-18.0254
c-0.1367-6.3506,2.5439-12.751,7.3545-17.5605c4.8521-4.8521,11.3037-7.5547,17.7383-7.417c4.3691,0,8.4863,1.1465,12.2314,3.4043
c3.7344,2.2979,6.7456,5.4053,8.9492,9.2354c2.1699,3.9072,3.2695,8.0967,3.2695,12.4697
c0.1396,6.4619-2.5967,12.9844-7.5083,17.8955c-4.7617,4.7617-11.0469,7.3857-17.2544,7.2803
C197.6856,129.9712,191.396,127.3208,186.6358,122.5591z"/>
<path d="M241.8955,80.3975h7.5669v42.0259c0,6.8174,4.5674,12.1309,11.0825,12.9189c0.6836,0.1055,1.8379,0.1572,3.5303,0.1572
c2.0078,0,3.0273-0.3535,3.0273-2.2842v-2.377c0-1.7891-1.334-2.0371-2.7568-2.0371c0,0-0.001,0-0.002,0l-1.7871-0.0488
c-2.0117-0.0439-3.4883-0.7627-4.3896-2.1367c-0.9697-1.4805-1.4619-3.1738-1.4619-5.0352V80.3975h10.0928
c1.3076,0,2.2852-1.3628,2.2852-2.5815v-1.9312c0-1.3999-0.8359-2.2354-2.2354-2.2354h-10.1426V60.6861
c0-1.4619-0.7969-2.4829-1.9375-2.4829c-0.1865,0-0.4121,0-0.6392,0.0884l-2.6489,0.6865
c-1.2109,0.3682-2.0171,0.9263-2.0171,2.4507v12.2207h-7.5669c-1.4185,0-2.335,0.897-2.335,2.2852v1.8813
C239.5606,79.2393,240.6079,80.3975,241.8955,80.3975z"/>
<path d="M379.1182,106.2691c-4.0488-2.9219-8.8545-5.0293-14.291-6.2646c-6.5049-1.3975-13.4473-5.2129-13.3203-10.3066
c0-7.5225,6.6367-10.1914,12.3203-10.1914c5.3574,0,10.2207,3.002,13.001,8.0146c0.6729,1.2861,1.4785,1.9375,2.3955,1.9375
c0.3311,0,0.7061-0.1113,0.9922-0.2832l2.2021-1.1523c0.5947-0.3408,0.9229-0.9414,0.9229-1.6924
c0-0.5205-0.0908-0.9541-0.2617-1.292c-3.6367-8.2466-10.0967-12.4282-19.2021-12.4282c-11.7305,0-19.6123,6.9263-19.6123,17.2349
c0,4.3125,1.8438,7.9746,5.4756,10.8809c3.4482,2.7979,7.9121,4.8623,13.2705,6.1377c4.5859,1.085,8.3193,2.5654,11.0977,4.4023
c1.4159,0.9354,2.4412,2.0535,3.106,3.3672c0.6053,1.1962,0.9135,2.5535,0.9135,4.1005c0.0742,2.3857-0.79,4.5176-2.5684,6.3389
c-3.1445,3.2178-8.4053,4.6689-12.0205,4.6689c-0.0361,0-0.0723,0-0.1074,0c-3.4268,0-6.4893-0.8438-9.1035-2.5068
c-2.5918-1.6484-4.2363-3.8076-5.0293-6.6064c-0.3203-1.0996-0.751-2.1738-2.1553-2.1738c-0.0742,0-0.2109,0.0146-0.4062,0.0449
c-0.1133,0.0166-0.2559,0.0381-0.5088,0.0742l-1.8818,0.4463l-0.1045,0.0332c-1.0244,0.4082-1.6113,1.1846-1.6113,2.1309
c0,0.2285,0.0625,0.6592,0.2178,1.1094c1.9707,8.5801,10.2432,14.3447,20.5732,14.3447c0.125,0.002,0.249,0.002,0.374,0.002
c6.5947,0,12.6748-2.3193,16.7275-6.3945c3.1895-3.208,4.8311-7.2363,4.748-11.6357c0-2.8187-0.6185-5.3109-1.8062-7.481
C382.4437,109.2624,381.0062,107.631,379.1182,106.2691z"/>
<path d="M348.9043,45.7325c0-6.3157-3.2826-11.8699-8.2238-15.0756c-2.811-1.8237-6.1537-2.8947-9.7469-2.8947
c-9.9092,0-17.9707,8.0615-17.9707,17.9702c0,4.7659,1.8775,9.0925,4.9157,12.3123c-3.6619,4.3709-6.6334,9.3336-8.7663,14.7186
c-1.5873-0.2422-3.2123-0.3683-4.8662-0.3683c-17.7158,0-32.1289,14.4131-32.1289,32.1289c0,14.6854,9.9077,27.0922,23.3869,30.9101
c-6.7762,17.3461-23.6572,29.6719-43.3742,29.6719c-16.8195,0-31.583-8.9662-39.7656-22.369
c-2.4778,0.5446-5.0429,0.8519-7.6721,0.9023c9.0226,16.99,26.8969,28.5917,47.4377,28.5917
c23.2646,0,43.1121-14.8788,50.5461-35.6179c0.5204,0.0251,1.0435,0.0398,1.5701,0.0398c17.7158,0,32.1289-14.4131,32.1289-32.1289
c0-13.557-8.4446-25.1712-20.3465-29.8811c1.9001-4.5678,4.5115-8.7646,7.6888-12.4641c0.9996,0.4404,2.0479,0.785,3.1324,1.0384
c1.3144,0.3071,2.6773,0.486,4.0839,0.486C340.8428,63.7032,348.9043,55.6416,348.9043,45.7325z M304.2461,129.5279
c-13.7871,0-25.0039-11.2168-25.0039-25.0039s11.2168-25.0039,25.0039-25.0039S329.25,90.7369,329.25,104.524
S318.0332,129.5279,304.2461,129.5279z M330.9336,34.8872c0.645,0,1.2737,0.0671,1.8881,0.1755
c5.0818,0.8974,8.9576,5.3347,8.9576,10.6697c0,5.9805-4.8652,10.8457-10.8457,10.8457s-10.8457-4.8652-10.8457-10.8457
c0-1.3967,0.2746-2.7282,0.7576-3.9555C322.4306,37.7496,326.35,34.8872,330.9336,34.8872z"/>
</svg>

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 27.1.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 437.4294 209.6185" style="enable-background:new 0 0 437.4294 209.6185;" xml:space="preserve">
<path style="fill:#FFFFFF;" d="M95.1109,128.1089H58.6797V65.6861c0-1.5234-0.8169-2.4331-2.1855-2.4331h-3.1187
c-1.3159,0-2.2349,1.0005-2.2349,2.4331v67.4297c0,1.4521,0.8145,2.2852,2.2349,2.2852h41.7353c1.4844,0,2.4819-0.9375,2.4819-2.333
v-2.7744C97.5928,128.9253,96.6651,128.1089,95.1109,128.1089z"/>
<path style="fill:#FFFFFF;" d="M146.4561,77.1739c-4.8252-3.001-10.3037-4.5249-16.2837-4.5288c-0.0068,0-0.0137,0-0.0205,0
c-5.7349,0-11.1377,1.4639-16.0566,4.3511c-4.916,2.8853-8.8721,6.8364-11.7593,11.7456
c-2.8975,4.9248-4.3687,10.332-4.3721,16.0713c-0.0034,5.7188,1.4966,11.0654,4.4565,15.8887
c2.9893,4.9209,6.8789,8.7334,11.8887,11.6514c4.8657,2.8633,10.2397,4.3174,15.9717,4.3203c0.0073,0,0.0146,0,0.022,0
c8.123,0,14.7441-2.5869,21.4683-8.3906c0.5493-0.4805,0.8516-1.1201,0.8516-1.8008c0.001-0.6074-0.1743-1.1035-0.5205-1.4756
l-1.3569-1.8428l-0.0732-0.0859c-0.2637-0.2637-0.6929-0.6152-1.3716-0.6152c-0.6421,0-1.2549,0.2217-1.7124,0.6143
c-1.9346,1.585-3.5459,2.8008-4.7969,3.6182c-1.7979,1.208-5.8218,3.2314-12.5986,3.2314c-0.0073,0-0.0142,0-0.021,0
c-0.1357,0.0029-0.269,0.0039-0.4043,0.0039c-12.2642,0-23.4736-10.3262-24.5088-22.4814l53.0127,0.0322c0.0015,0,0.0024,0,0.0034,0
c2.2373,0,3.4697-1.1621,3.4712-3.2715c0.0034-5.2588-1.3574-10.3945-4.0464-15.2705
C155.0015,84.0953,151.2188,80.1363,146.4561,77.1739z M154.6451,100.4341l-49.1157-0.0293
c1.9834-11.6631,13.0181-21.2417,24.5034-21.0117c0.1387-0.0024,0.2754-0.0039,0.4136-0.0039
C143.4629,79.3892,152.4722,90.0162,154.6451,100.4341z"/>
<path style="fill:#FFFFFF;" d="M204.0386,136.6382c5.7319,0,11.1069-1.4502,15.9746-4.3115
c4.938-2.9014,8.75-6.7129,11.6533-11.6533c2.8608-4.8672,4.311-10.2578,4.311-16.0244c0-5.7324-1.4502-11.1064-4.311-15.9746
c-2.9019-4.9385-6.7134-8.75-11.6533-11.6533c-4.8687-2.8618-10.2437-4.3125-15.9746-4.3125
c-9.938,0-19.2021,4.7583-24.3516,12.3174v-9.438c0-0.5946-0.1465-1.0788-0.411-1.4511c-0.3815-0.5369-1.0157-0.834-1.8727-0.834
h-2.6738c-1.4521,0-2.2852,0.833-2.2852,2.2852v5.6964v46.4791v23.9676c0,1.2568,0.7808,2.0371,2.0371,2.0371h3.3667
c0.9209,0,1.6421-0.6992,1.6421-1.5908v-17.098v-10.984C185.0884,131.8892,194.2749,136.6382,204.0386,136.6382z M186.6358,122.5591
c-4.9346-4.9346-7.6831-11.4932-7.542-18.0254c-0.1367-6.3506,2.5439-12.751,7.3545-17.5605
c4.8521-4.8521,11.3037-7.5547,17.7383-7.417c4.3691,0,8.4863,1.1465,12.2314,3.4043c3.7344,2.2979,6.7456,5.4053,8.9492,9.2354
c2.1699,3.9072,3.2695,8.0967,3.2695,12.4697c0.1396,6.4619-2.5967,12.9844-7.5083,17.8955
c-4.7617,4.7617-11.0469,7.3857-17.2544,7.2803C197.6856,129.9712,191.396,127.3208,186.6358,122.5591z"/>
<path style="fill:#FFFFFF;" d="M241.8955,80.3975h7.5669v42.0259c0,6.8174,4.5674,12.1309,11.0825,12.9189
c0.6836,0.1055,1.8379,0.1572,3.5303,0.1572c2.0078,0,3.0273-0.3535,3.0273-2.2842v-2.377c0-1.7891-1.334-2.0371-2.7568-2.0371
c0,0-0.001,0-0.002,0l-1.7871-0.0488c-2.0117-0.0439-3.4883-0.7627-4.3896-2.1367c-0.9697-1.4805-1.4619-3.1738-1.4619-5.0352
V80.3975h10.0928c1.3076,0,2.2852-1.3628,2.2852-2.5815v-1.9312c0-1.3999-0.8359-2.2354-2.2354-2.2354h-10.1426V60.6861
c0-1.4619-0.7969-2.4829-1.9375-2.4829c-0.1865,0-0.4121,0-0.6392,0.0884l-2.6489,0.6865
c-1.2109,0.3682-2.0171,0.9263-2.0171,2.4507v12.2207h-7.5669c-1.4185,0-2.335,0.897-2.335,2.2852v1.8813
C239.5606,79.2393,240.6079,80.3975,241.8955,80.3975z"/>
<path style="fill:#FFFFFF;" d="M379.1182,106.2691c-4.0488-2.9219-8.8545-5.0293-14.291-6.2646
c-6.5049-1.3975-13.4473-5.2129-13.3203-10.3066c0-7.5225,6.6367-10.1914,12.3203-10.1914c5.3574,0,10.2207,3.002,13.001,8.0146
c0.6729,1.2861,1.4785,1.9375,2.3955,1.9375c0.3311,0,0.7061-0.1113,0.9922-0.2832l2.2021-1.1523
c0.5947-0.3408,0.9229-0.9414,0.9229-1.6924c0-0.5205-0.0908-0.9541-0.2617-1.292c-3.6367-8.2466-10.0967-12.4282-19.2021-12.4282
c-11.7305,0-19.6123,6.9263-19.6123,17.2349c0,4.3125,1.8438,7.9746,5.4756,10.8809c3.4482,2.7979,7.9121,4.8623,13.2705,6.1377
c4.5859,1.085,8.3193,2.5654,11.0977,4.4023c1.4159,0.9354,2.4412,2.0535,3.106,3.3672c0.6053,1.1962,0.9135,2.5535,0.9135,4.1005
c0.0742,2.3857-0.79,4.5176-2.5684,6.3389c-3.1445,3.2178-8.4053,4.6689-12.0205,4.6689c-0.0361,0-0.0723,0-0.1074,0
c-3.4268,0-6.4893-0.8438-9.1035-2.5068c-2.5918-1.6484-4.2363-3.8076-5.0293-6.6064c-0.3203-1.0996-0.751-2.1738-2.1553-2.1738
c-0.0742,0-0.2109,0.0146-0.4062,0.0449c-0.1133,0.0166-0.2559,0.0381-0.5088,0.0742l-1.8818,0.4463l-0.1045,0.0332
c-1.0244,0.4082-1.6113,1.1846-1.6113,2.1309c0,0.2285,0.0625,0.6592,0.2178,1.1094c1.9707,8.5801,10.2432,14.3447,20.5732,14.3447
c0.125,0.002,0.249,0.002,0.374,0.002c6.5947,0,12.6748-2.3193,16.7275-6.3945c3.1895-3.208,4.8311-7.2363,4.748-11.6357
c0-2.8187-0.6185-5.3109-1.8062-7.481C382.4437,109.2624,381.0062,107.631,379.1182,106.2691z"/>
<path style="fill:#FFFFFF;" d="M348.9043,45.7325c0-6.3157-3.2826-11.8699-8.2238-15.0756
c-2.811-1.8237-6.1537-2.8947-9.7469-2.8947c-9.9092,0-17.9707,8.0615-17.9707,17.9702c0,4.7659,1.8775,9.0925,4.9157,12.3123
c-3.6619,4.3709-6.6334,9.3336-8.7663,14.7186c-1.5873-0.2422-3.2123-0.3683-4.8662-0.3683
c-17.7158,0-32.1289,14.4131-32.1289,32.1289c0,14.6854,9.9077,27.0922,23.3869,30.9101
c-6.7762,17.3461-23.6572,29.6719-43.3742,29.6719c-16.8195,0-31.583-8.9662-39.7656-22.369
c-2.4778,0.5446-5.0429,0.8519-7.6721,0.9023c9.0226,16.99,26.8969,28.5917,47.4377,28.5917
c23.2646,0,43.1121-14.8788,50.5461-35.6179c0.5204,0.0251,1.0435,0.0398,1.5701,0.0398c17.7158,0,32.1289-14.4131,32.1289-32.1289
c0-13.557-8.4446-25.1712-20.3465-29.8811c1.9001-4.5678,4.5115-8.7646,7.6888-12.4641c0.9996,0.4404,2.0479,0.785,3.1324,1.0384
c1.3144,0.3071,2.6773,0.486,4.0839,0.486C340.8428,63.7032,348.9043,55.6416,348.9043,45.7325z M304.2461,129.5279
c-13.7871,0-25.0039-11.2168-25.0039-25.0039s11.2168-25.0039,25.0039-25.0039S329.25,90.7369,329.25,104.524
S318.0332,129.5279,304.2461,129.5279z M330.9336,34.8872c0.645,0,1.2737,0.0671,1.8881,0.1755
c5.0818,0.8974,8.9576,5.3347,8.9576,10.6697c0,5.9805-4.8652,10.8457-10.8457,10.8457s-10.8457-4.8652-10.8457-10.8457
c0-1.3967,0.2746-2.7282,0.7576-3.9555C322.4306,37.7496,326.35,34.8872,330.9336,34.8872z"/>
</svg>

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 27.1.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 115.9988 115.9988" style="enable-background:new 0 0 115.9988 115.9988;" xml:space="preserve">
<g>
<g>
<g>
<path style="fill:#180D38;" d="M29.1281,108.2941c9.5736-4.5548,17.1531-12.6456,21.0335-22.5787
c-12.0865-3.4232-20.9707-14.548-20.9707-27.7159c0-15.8849,12.9236-28.8085,28.8085-28.8085
c1.4832,0,2.9404,0.113,4.3639,0.3303c1.9125-4.8287,4.5771-9.2786,7.8607-13.1979c-2.7243-2.8871-4.4077-6.7665-4.4077-11.0399
c0-1.6191,0.2457-3.1808,0.6921-4.6562C63.7305,0.2186,60.8908,0,57.9995,0C25.9672,0,0,25.9672,0,57.9994
C0,79.5165,11.7263,98.2828,29.1281,108.2941z"/>
<path style="fill:#EF3939;" d="M81.9297,15.0082c3.6788,0,6.886-2.0536,8.5379-5.0742
c-5.3185-3.5997-11.2684-6.3339-17.646-8.0151c-0.3903,1.0504-0.6168,2.1798-0.6168,3.3644
C72.2049,10.6458,76.5673,15.0082,81.9297,15.0082z"/>
<path style="fill:#180D38;" d="M95.5663,13.828c-2.8537,4.5375-7.8918,7.5688-13.6366,7.5688
c-1.2614,0-2.4835-0.1604-3.6622-0.4359c-0.9722-0.2272-1.9121-0.5362-2.8083-0.931c-2.8492,3.3173-5.1907,7.0806-6.8945,11.1766
c10.6715,4.2233,18.2432,14.6371,18.2432,26.7928c0,15.8849-12.9235,28.8085-28.8085,28.8085
c-0.4718,0-0.9406-0.0131-1.4069-0.0357c-3.7532,10.4704-11.0354,19.2744-20.406,24.9696
c6.7355,2.7367,14.0948,4.257,21.8129,4.257c32.0322,0,57.9994-25.9672,57.9994-57.9995
C115.9988,40.3018,108.0628,24.4664,95.5663,13.828z"/>
<circle style="fill:#EF3939;" cx="57.9994" cy="57.9994" r="22.4198"/>
</g>
<path style="fill:#FFFFFF;" d="M78.2676,20.961c1.1786,0.2755,2.4008,0.4359,3.6622,0.4359
c5.7448,0,10.7829-3.0313,13.6366-7.5688c-1.6275-1.3855-3.3236-2.6925-5.0987-3.894c-1.6519,3.0206-4.8591,5.0742-8.5379,5.0742
c-5.3624,0-9.7249-4.3624-9.7249-9.7249c0-1.1846,0.2264-2.3141,0.6168-3.3644c-2.062-0.5436-4.1682-0.9763-6.3133-1.2917
c-0.4464,1.4753-0.6921,3.0371-0.6921,4.6562c0,4.2734,1.6834,8.1528,4.4077,11.0399c-3.2836,3.9193-5.9482,8.3692-7.8607,13.1979
c-1.4235-0.2172-2.8807-0.3303-4.3639-0.3303c-15.8849,0-28.8085,12.9235-28.8085,28.8085
c0,13.168,8.8842,24.2928,20.9707,27.7159c-3.8804,9.9332-11.4599,18.0239-21.0335,22.5787
c2.2621,1.3013,4.6175,2.456,7.0584,3.4478c9.3706-5.6952,16.6528-14.4992,20.406-24.9696
c0.4663,0.0226,0.9351,0.0357,1.4069,0.0357c15.8849,0,28.8085-12.9236,28.8085-28.8085c0-12.1557-7.5717-22.5695-18.2432-26.7928
c1.7038-4.0959,4.0453-7.8593,6.8945-11.1766C76.3555,20.4248,77.2953,20.7338,78.2676,20.961z M80.4193,57.9994
c0,12.3623-10.0576,22.4199-22.4198,22.4199c-12.3623,0-22.4199-10.0576-22.4199-22.4199
c0-12.3622,10.0576-22.4199,22.4199-22.4199C70.3617,35.5795,80.4193,45.6371,80.4193,57.9994z"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 27.1.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 115.5026 115.5026" style="enable-background:new 0 0 115.5026 115.5026;" xml:space="preserve">
<path style="fill:#181139;" d="M115.5026,0h-13.957c0.0002,0.0315,0.0031,0.0623,0.0031,0.0938
c0,9.718-7.9059,17.6239-17.6239,17.6239c-1.3796,0-2.7163-0.1754-4.0055-0.4767c-1.0634-0.2485-2.0913-0.5864-3.0715-1.0182
c-3.1162,3.6283-5.6772,7.7443-7.5408,12.2242c11.6719,4.6192,19.9532,16.0091,19.9532,29.3043
c0,17.374-14.1349,31.5089-31.5089,31.5089c-0.5161,0-1.0288-0.0143-1.5388-0.039c-3.8856,10.8397-11.2302,20.0454-20.6959,26.2814
h79.986V0z"/>
<circle style="fill:#EF3939;" cx="57.7513" cy="57.7513" r="24.5214"/>
<path style="fill:#181139;" d="M49.1788,88.0652c-13.2195-3.744-22.9364-15.9116-22.9364-30.3139
c0-17.374,14.1349-31.5089,31.5089-31.5089c1.6223,0,3.2161,0.1237,4.7729,0.3612c2.0918-5.2813,5.0061-10.1484,8.5975-14.4351
c-2.9796-3.1577-4.8209-7.4008-4.8209-12.0747c0-0.0317,0.0046-0.0622,0.0048-0.0938H0v115.5026h18.8623
C32.7495,111.6378,43.9877,101.3537,49.1788,88.0652z"/>
<path style="fill:#EF3939;" d="M83.9248,10.7302c5.8651,0,10.6364-4.7714,10.6364-10.6364c0-0.0316-0.004-0.0623-0.0043-0.0938
H73.293c-0.0003,0.0316-0.0046,0.0621-0.0046,0.0938C73.2884,5.9589,78.0598,10.7302,83.9248,10.7302z"/>
<path style="fill:#FFFFFF;" d="M56.2125,89.2212c0.51,0.0247,1.0228,0.039,1.5388,0.039c17.374,0,31.5089-14.1349,31.5089-31.5089
c0-13.2952-8.2814-24.6851-19.9532-29.3043c1.8635-4.4799,4.4246-8.5959,7.5408-12.2242c0.9802,0.4318,2.0082,0.7698,3.0715,1.0182
c1.2892,0.3013,2.6259,0.4767,4.0055,0.4767c9.718,0,17.6239-7.9059,17.6239-17.6239c0-0.0315-0.0029-0.0623-0.0031-0.0938h-6.9887
c0.0003,0.0316,0.0043,0.0622,0.0043,0.0938c0,5.8651-4.7714,10.6364-10.6364,10.6364S73.2884,5.9589,73.2884,0.0938
c0-0.0317,0.0043-0.0622,0.0046-0.0938h-6.9874c-0.0002,0.0316-0.0048,0.0621-0.0048,0.0938c0,4.674,1.8413,8.9171,4.8209,12.0747
c-3.5914,4.2867-6.5057,9.1537-8.5975,14.4351c-1.5569-0.2375-3.1507-0.3612-4.7729-0.3612
c-17.374,0-31.5089,14.1349-31.5089,31.5089c0,14.4023,9.7169,26.5699,22.9364,30.3139
c-5.1912,13.2885-16.4293,23.5726-30.3165,27.4374h16.6543C44.9824,109.2666,52.327,100.0609,56.2125,89.2212z M33.2299,57.7513
c0-13.5211,11.0004-24.5214,24.5214-24.5214s24.5214,11.0004,24.5214,24.5214S71.2724,82.2727,57.7513,82.2727
S33.2299,71.2723,33.2299,57.7513z"/>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 437.4 209.6" style="enable-background:new 0 0 437.4 209.6;" xmlns="http://www.w3.org/2000/svg">
<style type="text/css">
.st0{fill:#FFFFFF;}
.st1{fill:#EF3939;}
</style>
<path class="st0" d="M95.1,128.1H58.7V65.7c0-1.5-0.8-2.4-2.2-2.4h-3.1c-1.3,0-2.2,1-2.2,2.4v67.4c0,1.5,0.8,2.3,2.2,2.3h41.7 c1.5,0,2.5-0.9,2.5-2.3v-2.8C97.6,128.9,96.7,128.1,95.1,128.1z"/>
<path class="st0" d="M146.5,77.2c-4.8-3-10.3-4.5-16.3-4.5c0,0,0,0,0,0c-5.7,0-11.1,1.5-16.1,4.4c-4.9,2.9-8.9,6.8-11.8,11.7 c-2.9,4.9-4.4,10.3-4.4,16.1c0,5.7,1.5,11.1,4.5,15.9c3,4.9,6.9,8.7,11.9,11.7c4.9,2.9,10.2,4.3,16,4.3c0,0,0,0,0,0 c8.1,0,14.7-2.6,21.5-8.4c0.5-0.5,0.9-1.1,0.9-1.8c0-0.6-0.2-1.1-0.5-1.5l-1.4-1.8l-0.1-0.1c-0.3-0.3-0.7-0.6-1.4-0.6 c-0.6,0-1.3,0.2-1.7,0.6c-1.9,1.6-3.5,2.8-4.8,3.6c-1.8,1.2-5.8,3.2-12.6,3.2c0,0,0,0,0,0c-0.1,0-0.3,0-0.4,0 c-12.3,0-23.5-10.3-24.5-22.5l53,0c0,0,0,0,0,0c2.2,0,3.5-1.2,3.5-3.3c0-5.3-1.4-10.4-4-15.3C155,84.1,151.2,80.1,146.5,77.2z M154.6,100.4l-49.1,0c2-11.7,13-21.2,24.5-21c0.1,0,0.3,0,0.4,0C143.5,79.4,152.5,90,154.6,100.4z"/>
<path class="st0" d="M204,136.6c5.7,0,11.1-1.5,16-4.3c4.9-2.9,8.8-6.7,11.7-11.7c2.9-4.9,4.3-10.3,4.3-16c0-5.7-1.5-11.1-4.3-16 c-2.9-4.9-6.7-8.8-11.7-11.7c-4.9-2.9-10.2-4.3-16-4.3c-9.9,0-19.2,4.8-24.4,12.3v-9.4c0-0.6-0.1-1.1-0.4-1.5 c-0.4-0.5-1-0.8-1.9-0.8h-2.7c-1.5,0-2.3,0.8-2.3,2.3v5.7v46.5v24c0,1.3,0.8,2,2,2h3.4c0.9,0,1.6-0.7,1.6-1.6v-17.1v-11 C185.1,131.9,194.3,136.6,204,136.6z M186.6,122.6c-4.9-4.9-7.7-11.5-7.5-18c-0.1-6.4,2.5-12.8,7.4-17.6c4.9-4.9,11.3-7.6,17.7-7.4 c4.4,0,8.5,1.1,12.2,3.4c3.7,2.3,6.7,5.4,8.9,9.2c2.2,3.9,3.3,8.1,3.3,12.5c0.1,6.5-2.6,13-7.5,17.9c-4.8,4.8-11,7.4-17.3,7.3 C197.7,130,191.4,127.3,186.6,122.6z"/>
<path class="st0" d="M241.9,80.4h7.6v42c0,6.8,4.6,12.1,11.1,12.9c0.7,0.1,1.8,0.2,3.5,0.2c2,0,3-0.4,3-2.3v-2.4c0-1.8-1.3-2-2.8-2 c0,0,0,0,0,0l-1.8,0c-2,0-3.5-0.8-4.4-2.1c-1-1.5-1.5-3.2-1.5-5V80.4h10.1c1.3,0,2.3-1.4,2.3-2.6v-1.9c0-1.4-0.8-2.2-2.2-2.2h-10.1 v-13c0-1.5-0.8-2.5-1.9-2.5c-0.2,0-0.4,0-0.6,0.1l-2.6,0.7c-1.2,0.4-2,0.9-2,2.5v12.2h-7.6c-1.4,0-2.3,0.9-2.3,2.3v1.9 C239.6,79.2,240.6,80.4,241.9,80.4z"/>
<path class="st0" d="M379.1,106.3c-4-2.9-8.9-5-14.3-6.3c-6.5-1.4-13.4-5.2-13.3-10.3c0-7.5,6.6-10.2,12.3-10.2c5.4,0,10.2,3,13,8 c0.7,1.3,1.5,1.9,2.4,1.9c0.3,0,0.7-0.1,1-0.3l2.2-1.2c0.6-0.3,0.9-0.9,0.9-1.7c0-0.5-0.1-1-0.3-1.3c-3.6-8.2-10.1-12.4-19.2-12.4 c-11.7,0-19.6,6.9-19.6,17.2c0,4.3,1.8,8,5.5,10.9c3.4,2.8,7.9,4.9,13.3,6.1c4.6,1.1,8.3,2.6,11.1,4.4c1.4,0.9,2.4,2.1,3.1,3.4 c0.6,1.2,0.9,2.6,0.9,4.1c0.1,2.4-0.8,4.5-2.6,6.3c-3.1,3.2-8.4,4.7-12,4.7c0,0-0.1,0-0.1,0c-3.4,0-6.5-0.8-9.1-2.5 c-2.6-1.6-4.2-3.8-5-6.6c-0.3-1.1-0.8-2.2-2.2-2.2c-0.1,0-0.2,0-0.4,0c-0.1,0-0.3,0-0.5,0.1l-1.9,0.4l-0.1,0c-1,0.4-1.6,1.2-1.6,2.1 c0,0.2,0.1,0.7,0.2,1.1c2,8.6,10.2,14.3,20.6,14.3c0.1,0,0.2,0,0.4,0c6.6,0,12.7-2.3,16.7-6.4c3.2-3.2,4.8-7.2,4.7-11.6 c0-2.8-0.6-5.3-1.8-7.5C382.4,109.3,381,107.6,379.1,106.3z"/>
<path class="st1" d="M348.9,45.7c0-6.3-3.3-11.9-8.2-15.1c-2.8-1.8-6.2-2.9-9.7-2.9c-9.9,0-18,8.1-18,18c0,4.8,1.9,9.1,4.9,12.3 c-3.7,4.4-6.6,9.3-8.8,14.7c-1.6-0.2-3.2-0.4-4.9-0.4c-17.7,0-32.1,14.4-32.1,32.1c0,14.7,9.9,27.1,23.4,30.9 c-6.8,17.3-23.7,29.7-43.4,29.7c-16.8,0-31.6-9-39.8-22.4c-2.5,0.5-5,0.9-7.7,0.9c9,17,26.9,28.6,47.4,28.6 c23.3,0,43.1-14.9,50.5-35.6c0.5,0,1,0,1.6,0c17.7,0,32.1-14.4,32.1-32.1c0-13.6-8.4-25.2-20.3-29.9c1.9-4.6,4.5-8.8,7.7-12.5 c1,0.4,2,0.8,3.1,1c1.3,0.3,2.7,0.5,4.1,0.5C340.8,63.7,348.9,55.6,348.9,45.7z M304.2,129.5c-13.8,0-25-11.2-25-25s11.2-25,25-25 s25,11.2,25,25S318,129.5,304.2,129.5z M330.9,34.9c0.6,0,1.3,0.1,1.9,0.2c5.1,0.9,9,5.3,9,10.7c0,6-4.9,10.8-10.8,10.8 s-10.8-4.9-10.8-10.8c0-1.4,0.3-2.7,0.8-4C322.4,37.7,326.4,34.9,330.9,34.9z"/>
</svg>

After

Width:  |  Height:  |  Size: 3.7 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 7.3 KiB

View File

@@ -1,16 +0,0 @@
[package]
name = "counter-client"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies]
console_log = "0.2"
leptos = { path = "../../../leptos", default-features = false, features = ["hydrate", "serde"] }
counter-isomorphic = { path = "../counter", default-features = false, features = ["hydrate"] }
log = "0.4"
wasm-bindgen = "0.2"
console_error_panic_hook = "0.1.7"

View File

@@ -1 +0,0 @@
wasm-pack build --target=web --release

View File

@@ -1,14 +0,0 @@
use counter_isomorphic::*;
use leptos::*;
use wasm_bindgen::prelude::wasm_bindgen;
#[wasm_bindgen]
pub fn main() {
console_error_panic_hook::set_once();
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
leptos::hydrate(body().unwrap(), |cx| {
view! { cx, <Counters/> }
});
}

View File

@@ -1,25 +0,0 @@
[package]
name = "counter-isomorphic"
version = "0.1.0"
edition = "2021"
[dependencies]
leptos = { path = "../../../leptos", default-features = false, features = ["serde"] }
leptos_router = { path = "../../../router", default-features = false }
broadcaster = "1"
console_log = "0.2"
futures = "0.3"
gloo = { git = "https://github.com/rustwasm/gloo" }
lazy_static = "1"
log = "0.4"
console_error_panic_hook = "0.1.7"
serde = { version = "1", features = ["derive"] }
[dependencies.web-sys]
version = "0.3"
[features]
default = ["csr"]
csr = ["leptos/csr", "leptos_router/csr"]
hydrate = ["leptos/hydrate", "leptos_router/hydrate"]
ssr = ["leptos/ssr", "leptos_router/ssr"]

View File

@@ -1,13 +0,0 @@
[package]
name = "counter-server"
version = "0.1.0"
edition = "2021"
[dependencies]
actix-files = "0.6"
actix-web = { version = "4" }
futures = "0.3"
leptos = { path = "../../../leptos", default-features = false, features = ["ssr", "serde"] }
leptos_router = { path = "../../../router", default-features = false, features = ["ssr"] }
counter-isomorphic = { path = "../counter", default-features = false, features = ["ssr"] }
lazy_static = "1"

View File

@@ -1,107 +0,0 @@
use actix_files::Files;
use actix_web::*;
use counter_isomorphic::*;
use leptos::*;
use leptos_router::*;
#[get("{tail:.*}")]
async fn render(req: HttpRequest) -> impl Responder {
let path = req.path();
let path = "http://leptos".to_string() + path;
println!("path = {path}");
HttpResponse::Ok().content_type("text/html").body(format!(
r#"<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Isomorphic Counter</title>
</head>
<body>
{}
</body>
<script type="module">import init, {{ main }} from './pkg/counter_client.js'; init().then(main);</script>
</html>"#,
run_scope({
move |cx| {
let integration = ServerIntegration { path: path.clone() };
provide_context(cx, RouterIntegrationContext::new(integration));
view! { cx, <Counters/>}
}
})
))
}
#[post("{tail:.*}")]
async fn handle_server_fns(
req: HttpRequest,
params: web::Path<String>,
body: web::Bytes,
) -> impl Responder {
let path = params.into_inner();
let accept_header = req
.headers()
.get("Accept")
.and_then(|value| value.to_str().ok());
if let Some(server_fn) = server_fn_by_path(path.as_str()) {
let body: &[u8] = &body;
match server_fn(&body).await {
Ok(serialized) => {
// if this is Accept: application/json then send a serialized JSON response
if let Some("application/json") = accept_header {
HttpResponse::Ok().body(serialized)
}
// otherwise, it's probably a <form> submit or something: redirect back to the referrer
else {
HttpResponse::SeeOther()
.insert_header(("Location", "/"))
.content_type("application/json")
.body(serialized)
}
}
Err(e) => {
eprintln!("server function error: {e:#?}");
HttpResponse::InternalServerError().body(e.to_string())
}
}
} else {
HttpResponse::BadRequest().body(format!("Could not find a server function at that route."))
}
}
#[get("/api/events")]
async fn counter_events() -> impl Responder {
use futures::StreamExt;
let stream =
futures::stream::once(async { counter_isomorphic::get_server_count().await.unwrap_or(0) })
.chain(COUNT_CHANNEL.clone())
.map(|value| {
Ok(web::Bytes::from(format!(
"event: message\ndata: {value}\n\n"
))) as Result<web::Bytes>
});
HttpResponse::Ok()
.insert_header(("Content-Type", "text/event-stream"))
.streaming(stream)
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
counter_isomorphic::register_server_functions();
HttpServer::new(|| {
App::new()
.service(Files::new("/pkg", "../client/pkg"))
.service(counter_events)
.service(handle_server_fns)
.service(render)
//.wrap(middleware::Compress::default())
})
.bind(("127.0.0.1", 8081))?
.run()
.await
}

View File

@@ -10,5 +10,7 @@ log = "0.4"
console_error_panic_hook = "0.1.7"
[dev-dependencies]
wasm-bindgen = "0.2"
wasm-bindgen-test = "0.3.0"
web-sys ="0.3"

View File

@@ -0,0 +1,9 @@
[tasks.build]
command = "cargo"
args = ["+nightly", "build-all-features"]
install_crate = "cargo-all-features"
[tasks.check]
command = "cargo"
args = ["+nightly", "check-all-features"]
install_crate = "cargo-all-features"

View File

@@ -0,0 +1,7 @@
# Leptos Counter Example
This example creates a simple counter in a client side rendered app with Rust and WASM!
To run it, just issue the `trunk serve --open` command in the example root. This will build the app, run it, and open a new browser to serve it.
> If you don't have `trunk` installed, [click here for install instructions.](https://trunkrs.dev/)

View File

@@ -2,6 +2,7 @@
<html>
<head>
<link data-trunk rel="rust" data-wasm-opt="z"/>
<link data-trunk rel="icon" type="image/ico" href="/public/favicon.ico"/>
</head>
<body></body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -1,26 +1,24 @@
use leptos::*;
pub fn simple_counter(cx: Scope) -> web_sys::Element {
let (value, set_value) = create_signal(cx, 0);
/// A simple counter component.
///
/// You can use doc comments like this to document your component.
#[component]
pub fn SimpleCounter(
cx: Scope,
/// The starting value for the counter
initial_value: i32,
/// The change that should be applied each time the button is clicked.
step: i32
) -> impl IntoView {
let (value, set_value) = create_signal(cx, initial_value);
view! { cx,
<div>
<MyComponent><p>"Here's the child"</p></MyComponent>
<button on:click=move |_| set_value(0)>"Clear"</button>
<button on:click=move |_| set_value.update(|value| *value -= 1)>"-1"</button>
<span>"Value: " {move || value().to_string()} "!"</span>
<button on:click=move |_| set_value.update(|value| *value += 1)>"+1"</button>
<button on:click=move |_| set_value.update(|value| *value -= step)>"-1"</button>
<span>"Value: " {value} "!"</span>
<button on:click=move |_| set_value.update(|value| *value += step)>"+1"</button>
</div>
}
}
#[component]
fn MyComponent(cx: Scope, children: Option<Box<dyn Fn() -> Vec<Element>>>) -> Element {
view! {
cx,
<my-component>
<p>"Here's the child you passed in: "</p>
<slot></slot>
</my-component>
}
}

View File

@@ -1,8 +1,13 @@
use counter::simple_counter;
use counter::*;
use leptos::*;
pub fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(simple_counter)
mount_to_body(|cx| view! { cx,
<SimpleCounter
initial_value=0
step=1
/>
})
}

View File

@@ -1,40 +1,156 @@
use counter::*;
use leptos::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_test::*;
wasm_bindgen_test_configure!(run_in_browser);
use leptos::*;
use web_sys::HtmlElement;
#[wasm_bindgen_test]
fn clear() {
let document = leptos::document();
let test_wrapper = document.create_element("section").unwrap();
document.body().unwrap().append_child(&test_wrapper);
// start by rendering our counter and mounting it to the DOM
// note that we start at the initial value of 10
mount_to(
test_wrapper.clone().unchecked_into(),
|cx| view! { cx, <SimpleCounter initial_value=10 step=1/> },
);
// now we extract the buttons by iterating over the DOM
// this would be easier if they had IDs
let div = test_wrapper.query_selector("div").unwrap().unwrap();
let clear = test_wrapper
.query_selector("button")
.unwrap()
.unwrap()
.unchecked_into::<web_sys::HtmlElement>();
// now let's click the `clear` button
clear.click();
// now let's test the <div> against the expected value
// we can do this by testing its `outerHTML`
assert_eq!(
div.outer_html(),
// here we spawn a mini reactive system, just to render the
// test case
run_scope(create_runtime(), |cx| {
// it's as if we're creating it with a value of 0, right?
let (value, set_value) = create_signal(cx, 0);
// we can remove the event listeners because they're not rendered to HTML
view! { cx,
<div>
<button>"Clear"</button>
<button>"-1"</button>
<span>"Value: " {value} "!"</span>
<button>"+1"</button>
</div>
}
// the view returned an HtmlElement<Div>, which is a smart pointer for
// a DOM element. So we can still just call .outer_html()
.outer_html()
})
);
// There's actually an easier way to do this...
// We can just test against a <SimpleCounter/> with the initial value 0
assert_eq!(test_wrapper.inner_html(), {
let comparison_wrapper = document.create_element("section").unwrap();
leptos::mount_to(
comparison_wrapper.clone().unchecked_into(),
|cx| view! { cx, <SimpleCounter initial_value=0 step=1/>},
);
comparison_wrapper.inner_html()
});
}
#[wasm_bindgen_test]
fn inc() {
mount_to_body(counter::simple_counter);
let document = leptos::document();
let div = document.query_selector("div").unwrap().unwrap();
let dec = div
let test_wrapper = document.create_element("section").unwrap();
document.body().unwrap().append_child(&test_wrapper);
mount_to(
test_wrapper.clone().unchecked_into(),
|cx| view! { cx, <SimpleCounter initial_value=0 step=1/> },
);
// You can do testing with vanilla DOM operations
let document = leptos::document();
let div = test_wrapper.query_selector("div").unwrap().unwrap();
let clear = div
.first_child()
.unwrap()
.dyn_into::<HtmlElement>()
.dyn_into::<web_sys::HtmlElement>()
.unwrap();
let dec = clear
.next_sibling()
.unwrap()
.dyn_into::<web_sys::HtmlElement>()
.unwrap();
let text = dec
.next_sibling()
.unwrap()
.dyn_into::<HtmlElement>()
.dyn_into::<web_sys::HtmlElement>()
.unwrap();
let inc = text
.next_sibling()
.unwrap()
.dyn_into::<HtmlElement>()
.dyn_into::<web_sys::HtmlElement>()
.unwrap();
inc.click();
inc.click();
assert_eq!(text.text_content(), Some("2".to_string()));
assert_eq!(text.text_content(), Some("Value: 2!".to_string()));
dec.click();
dec.click();
dec.click();
dec.click();
assert_eq!(text.text_content(), Some("-2".to_string()));
assert_eq!(text.text_content(), Some("Value: -2!".to_string()));
clear.click();
assert_eq!(text.text_content(), Some("Value: 0!".to_string()));
// Or you can test against a sample view!
assert_eq!(
div.outer_html(),
run_scope(create_runtime(), |cx| {
let (value, _) = create_signal(cx, 0);
view! { cx,
<div>
<button>"Clear"</button>
<button>"-1"</button>
<span>"Value: " {value} "!"</span>
<button>"+1"</button>
</div>
}
}
.outer_html())
);
inc.click();
assert_eq!(
div.outer_html(),
run_scope(create_runtime(), |cx| {
// because we've clicked, it's as if the signal is starting at 1
let (value, _) = create_signal(cx, 1);
view! { cx,
<div>
<button>"Clear"</button>
<button>"-1"</button>
<span>"Value: " {value} "!"</span>
<button>"+1"</button>
</div>
}
}
.outer_html())
);
}

View File

@@ -0,0 +1 @@
.leptos.kdl

View File

@@ -0,0 +1,89 @@
[package]
name = "counter_isomorphic"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies]
actix-files = { version = "0.6", optional = true }
actix-web = { version = "4", optional = true, features = ["macros"] }
broadcaster = "1"
console_log = "0.2"
console_error_panic_hook = "0.1"
futures = "0.3"
cfg-if = "1"
lazy_static = "1"
leptos = { path = "../../leptos", default-features = false, features = [
"serde",
] }
leptos_actix = { path = "../../integrations/actix", optional = true }
leptos_meta = { path = "../../meta", default-features = false }
leptos_router = { path = "../../router", default-features = false }
log = "0.4"
gloo-net = { git = "https://github.com/rustwasm/gloo" }
wasm-bindgen = "0.2"
serde = { version = "1", features = ["derive"] }
[features]
default = []
hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"]
ssr = [
"dep:actix-files",
"dep:actix-web",
"leptos/ssr",
"leptos_actix",
"leptos_meta/ssr",
"leptos_router/ssr",
]
stable = ["leptos/stable", "leptos_router/stable"]
[package.metadata.cargo-all-features]
denylist = ["actix-files", "actix-web", "leptos_actix", "stable"]
skip_feature_sets = [["ssr", "hydrate"]]
[package.metadata.leptos]
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
output-name = "counter_isomorphic"
# The site root folder is where cargo-leptos generate all output. WARNING: all content of this folder will be erased on a rebuild. Use it in your server setup.
# When NOT using cargo-leptos this must be updated to "." or the counters will not work. The above warning still applies if you do switch to cargo-leptos later.
site-root = "target/site"
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
# Defaults to pkg
site-pkg-dir = "pkg"
# [Optional] The source CSS file. If it ends with .sass or .scss then it will be compiled by dart-sass into CSS. The CSS is optimized by Lightning CSS before being written to <site-root>/<site-pkg>/app.css
# style-file = "src/styles/tailwind.css"
# [Optional] Files in the asset-dir will be copied to the site-root directory
assets-dir = "public"
# The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup.
site-addr = "127.0.0.1:3000"
# The port to use for automatic reload monitoring
reload-port = 3001
# [Optional] Command to use when running end2end tests. It will run in the end2end dir.
end2end-cmd = "npx playwright test"
# The browserlist query used for optimizing the CSS.
browserquery = "defaults"
# Set by cargo-leptos watch when building with tha tool. Controls whether autoreload JS will be included in the head
watch = false
# The environment Leptos will run in, usually either "DEV" or "PROD"
env = "DEV"
# The features to use when compiling the bin target
#
# Optional. Can be over-ridden with the command line parameter --bin-features
bin-features = ["ssr"]
# If the --no-default-features flag should be used when compiling the bin target
#
# Optional. Defaults to false.
bin-default-features = false
# The features to use when compiling the lib target
#
# Optional. Can be over-ridden with the command line parameter --lib-features
lib-features = ["hydrate"]
# If the --no-default-features flag should be used when compiling the lib target
#
# Optional. Defaults to false.
lib-default-features = false

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Greg Johnston
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,9 @@
[tasks.build]
command = "cargo"
args = ["+nightly", "build-all-features"]
install_crate = "cargo-all-features"
[tasks.check]
command = "cargo"
args = ["+nightly", "check-all-features"]
install_crate = "cargo-all-features"

View File

@@ -0,0 +1,43 @@
# Leptos Counter Isomorphic Example
This example demonstrates how to use a function isomorphically, to run a server side function from the browser and receive a result.
## Client Side Rendering
For this example the server must store the counter state since it can be modified by many users.
This means it is not possible to produce a working CSR-only version as a non-static server is required.
## Server Side Rendering with cargo-leptos
cargo-leptos is now the easiest and most featureful way to build server side rendered apps with hydration. It provides automatic recompilation of client and server code, wasm optimisation, CSS minification, and more! Check out more about it [here](https://github.com/akesson/cargo-leptos)
1. Install cargo-leptos
```bash
cargo install --locked cargo-leptos
```
2. Build the site in watch mode, recompiling on file changes
```bash
cargo leptos watch
```
Open browser on [http://localhost:3000/](http://localhost:3000/)
3. When ready to deploy, run
```bash
cargo leptos build --release
```
## Server Side Rendering without cargo-leptos
To run it as a server side app with hydration, you'll need to have wasm-pack installed.
0. Edit the `[package.metadata.leptos]` section and set `site-root` to `"."`. For examples with CSS you also want to change the path of the `<StyleSheet / >` component in the root component to point towards the CSS file in the root. This tells leptos that the WASM/JS files generated by wasm-pack are available at `./pkg` and that the CSS files are no longer processed by cargo-leptos. Building to alternative folders is not supported at this time. You'll also want to edit the call to `get_configuration()` to pass in `Some(Cargo.toml)`, so that Leptos will read the settings instead of cargo-leptos. If you do so, your file/folder names cannot include dashes.
1. Install wasm-pack
```bash
cargo install wasm-pack
```
2. Build the Webassembly used to hydrate the HTML from the server
```bash
wasm-pack build --target=web --debug --no-default-features --features=hydrate
```
3. Run the server to serve the Webassembly, JS, and HTML
```bash
cargo run --no-default-features --features=ssr
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -1,7 +1,6 @@
use leptos::*;
use leptos_router::*;
use std::fmt::Debug;
use leptos_meta::*;
#[cfg(feature = "ssr")]
use std::sync::atomic::{AtomicI32, Ordering};
@@ -9,13 +8,11 @@ use std::sync::atomic::{AtomicI32, Ordering};
#[cfg(feature = "ssr")]
use broadcaster::BroadcastChannel;
use serde::{Deserialize, Serialize};
#[cfg(feature = "ssr")]
pub fn register_server_functions() {
GetServerCount::register();
AdjustServerCount::register();
ClearServerCount::register();
_ = GetServerCount::register();
_ = AdjustServerCount::register();
_ = ClearServerCount::register();
}
#[cfg(feature = "ssr")]
@@ -25,13 +22,13 @@ static COUNT: AtomicI32 = AtomicI32::new(0);
lazy_static::lazy_static! {
pub static ref COUNT_CHANNEL: BroadcastChannel<i32> = BroadcastChannel::new();
}
#[server(GetServerCount)]
// "/api" is an optional prefix that allows you to locate server functions wherever you'd like on the server
#[server(GetServerCount, "/api")]
pub async fn get_server_count() -> Result<i32, ServerFnError> {
Ok(COUNT.load(Ordering::Relaxed))
}
#[server(AdjustServerCount)]
#[server(AdjustServerCount, "/api")]
pub async fn adjust_server_count(delta: i32, msg: String) -> Result<i32, ServerFnError> {
let new = COUNT.load(Ordering::Relaxed) + delta;
COUNT.store(new, Ordering::Relaxed);
@@ -40,49 +37,48 @@ pub async fn adjust_server_count(delta: i32, msg: String) -> Result<i32, ServerF
Ok(new)
}
#[server(ClearServerCount)]
#[server(ClearServerCount, "/api")]
pub async fn clear_server_count() -> Result<i32, ServerFnError> {
COUNT.store(0, Ordering::Relaxed);
_ = COUNT_CHANNEL.send(&0).await;
Ok(0)
}
#[component]
pub fn Counters(cx: Scope) -> Element {
pub fn Counters(cx: Scope) -> impl IntoView {
provide_meta_context(cx);
view! {
cx,
<div>
<Router>
<header>
<h1>"Server-Side Counters"</h1>
<p>"Each of these counters stores its data in the same variable on the server."</p>
<p>"The value is shared across connections. Try opening this is another browser tab to see what I mean."</p>
</header>
<nav>
<ul>
<li><A href="">"Simple"</A></li>
<li><A href="form">"Form-Based"</A></li>
<li><A href="multi">"Multi-User"</A></li>
</ul>
</nav>
<main>
<Routes>
<Route path="" element=|cx| view! {
cx,
<Counter/>
}/>
<Route path="form" element=|cx| view! {
cx,
<FormCounter/>
}/>
<Route path="multi" element=|cx| view! {
cx,
<MultiuserCounter/>
}/>
</Routes>
</main>
</Router>
</div>
<Router>
<header>
<h1>"Server-Side Counters"</h1>
<p>"Each of these counters stores its data in the same variable on the server."</p>
<p>"The value is shared across connections. Try opening this is another browser tab to see what I mean."</p>
</header>
<nav>
<ul>
<li><A href="">"Simple"</A></li>
<li><A href="form">"Form-Based"</A></li>
<li><A href="multi">"Multi-User"</A></li>
</ul>
</nav>
<Link rel="shortcut icon" type_="image/ico" href="/favicon.ico"/>
<main>
<Routes>
<Route path="" view=|cx| view! {
cx,
<Counter/>
}/>
<Route path="form" view=|cx| view! {
cx,
<FormCounter/>
}/>
<Route path="multi" view=|cx| view! {
cx,
<MultiuserCounter/>
}/>
</Routes>
</main>
</Router>
}
}
@@ -91,20 +87,20 @@ pub fn Counters(cx: Scope) -> Element {
// it's invalidated by one of the user's own actions
// This is the typical pattern for a CRUD app
#[component]
pub fn Counter(cx: Scope) -> Element {
pub fn Counter(cx: Scope) -> impl IntoView {
let dec = create_action(cx, |_| adjust_server_count(-1, "decing".into()));
let inc = create_action(cx, |_| adjust_server_count(1, "incing".into()));
let clear = create_action(cx, |_| clear_server_count());
let counter = create_resource(
cx,
move || (dec.version.get(), inc.version.get(), clear.version.get()),
move || (dec.version().get(), inc.version().get(), clear.version().get()),
|_| get_server_count(),
);
let value = move || counter.read().map(|count| count.unwrap_or(0)).unwrap_or(0);
let value = move || counter.read(cx).map(|count| count.unwrap_or(0)).unwrap_or(0);
let error_msg = move || {
counter
.read()
.read(cx)
.map(|res| match res {
Ok(_) => None,
Err(e) => Some(e),
@@ -120,9 +116,10 @@ pub fn Counter(cx: Scope) -> Element {
<div>
<button on:click=move |_| clear.dispatch(())>"Clear"</button>
<button on:click=move |_| dec.dispatch(())>"-1"</button>
<span>"Value: " {move || value().to_string()} "!"</span>
<span>"Value: " {value} "!"</span>
<button on:click=move |_| inc.dispatch(())>"+1"</button>
</div>
{move || error_msg().map(|msg| view! { cx, <p>"Error: " {msg.to_string()}</p>})}
</div>
}
}
@@ -131,35 +128,28 @@ pub fn Counter(cx: Scope) -> Element {
// It uses the same invalidation pattern as the plain counter,
// but uses HTML forms to submit the actions
#[component]
pub fn FormCounter(cx: Scope) -> Element {
pub fn FormCounter(cx: Scope) -> impl IntoView {
let adjust = create_server_action::<AdjustServerCount>(cx);
let clear = create_server_action::<ClearServerCount>(cx);
let counter = create_resource(
cx,
{
let adjust = adjust.version;
let clear = clear.version;
move || (adjust.get(), clear.get())
},
move || (adjust.version().get(), clear.version().get()),
|_| {
log::debug!("FormCounter running fetcher");
get_server_count()
},
);
let value = move || {
log::debug!("FormCounter looking for value");
counter
.read()
.read(cx)
.map(|n| n.ok())
.flatten()
.map(|n| n)
.unwrap_or(0)
};
let adjust2 = adjust.clone();
view! {
cx,
<div>
@@ -175,13 +165,13 @@ pub fn FormCounter(cx: Scope) -> Element {
// by including them as input values with the same name
<ActionForm action=adjust>
<input type="hidden" name="delta" value="-1"/>
<input type="hidden" name="msg" value="\"form value down\""/>
<input type="hidden" name="msg" value="form value down"/>
<input type="submit" value="-1"/>
</ActionForm>
<span>"Value: " {move || value().to_string()} "!"</span>
<ActionForm action=adjust2>
<ActionForm action=adjust>
<input type="hidden" name="delta" value="1"/>
<input type="hidden" name="msg" value="\"form value up\""/>
<input type="hidden" name="msg" value="form value up"/>
<input type="submit" value="+1"/>
</ActionForm>
</div>
@@ -194,7 +184,7 @@ pub fn FormCounter(cx: Scope) -> Element {
// Whenever another user updates the value, it will update here
// This is the primitive pattern for live chat, collaborative editing, etc.
#[component]
pub fn MultiuserCounter(cx: Scope) -> Element {
pub fn MultiuserCounter(cx: Scope) -> impl IntoView {
let dec = create_action(cx, |_| adjust_server_count(-1, "dec dec goose".into()));
let inc = create_action(cx, |_| adjust_server_count(1, "inc inc moose".into()));
let clear = create_action(cx, |_| clear_server_count());
@@ -203,17 +193,17 @@ pub fn MultiuserCounter(cx: Scope) -> Element {
let multiplayer_value = {
use futures::StreamExt;
let mut source = gloo::net::eventsource::futures::EventSource::new("/api/events")
.expect_throw("couldn't connect to SSE stream");
let mut source = gloo_net::eventsource::futures::EventSource::new("/api/events")
.expect("couldn't connect to SSE stream");
let s = create_signal_from_stream(
cx,
source.subscribe("message").unwrap().map(|value| {
value
.expect_throw("no message event")
.expect("no message event")
.1
.data()
.as_string()
.expect_throw("expected string value")
.expect("expected string value")
}),
);
@@ -222,8 +212,8 @@ pub fn MultiuserCounter(cx: Scope) -> Element {
};
#[cfg(feature = "ssr")]
let multiplayer_value =
create_signal_from_stream(cx, futures::stream::once(Box::pin(async { 0.to_string() })));
let (multiplayer_value, _) =
create_signal(cx, None::<i32>);
view! {
cx,
@@ -233,7 +223,7 @@ pub fn MultiuserCounter(cx: Scope) -> Element {
<div>
<button on:click=move |_| clear.dispatch(())>"Clear"</button>
<button on:click=move |_| dec.dispatch(())>"-1"</button>
<span>"Multiplayer Value: " {move || multiplayer_value().unwrap_or_default().to_string()}</span>
<span>"Multiplayer Value: " {move || multiplayer_value.get().unwrap_or_default().to_string()}</span>
<button on:click=move |_| inc.dispatch(())>"+1"</button>
</div>
</div>

View File

@@ -0,0 +1,21 @@
use cfg_if::cfg_if;
use leptos::*;
pub mod counters;
// Needs to be in lib.rs AFAIK because wasm-bindgen needs us to be compiling a lib. I may be wrong.
cfg_if! {
if #[cfg(feature = "hydrate")] {
use wasm_bindgen::prelude::wasm_bindgen;
use crate::counters::*;
#[wasm_bindgen]
pub fn hydrate() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(|cx| {
view! { cx, <Counters/> }
});
}
}
}

View File

@@ -0,0 +1,67 @@
use cfg_if::cfg_if;
use leptos::*;
mod counters;
// boilerplate to run in different modes
cfg_if! {
// server-only stuff
if #[cfg(feature = "ssr")] {
use actix_files::{Files};
use actix_web::*;
use crate::counters::*;
use leptos_actix::{generate_route_list, LeptosRoutes};
#[get("/api/events")]
async fn counter_events() -> impl Responder {
use futures::StreamExt;
let stream =
futures::stream::once(async { crate::counters::get_server_count().await.unwrap_or(0) })
.chain(COUNT_CHANNEL.clone())
.map(|value| {
Ok(web::Bytes::from(format!(
"event: message\ndata: {value}\n\n"
))) as Result<web::Bytes>
});
HttpResponse::Ok()
.insert_header(("Content-Type", "text/event-stream"))
.streaming(stream)
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
crate::counters::register_server_functions();
// Setting this to None means we'll be using cargo-leptos and its env vars.
// when not using cargo-leptos None must be replaced with Some("Cargo.toml")
let conf = get_configuration(None).await.unwrap();
let addr = conf.leptos_options.site_addr.clone();
let routes = generate_route_list(|cx| view! { cx, <Counters/> });
HttpServer::new(move || {
let leptos_options = &conf.leptos_options;
let site_root = &leptos_options.site_root;
App::new()
.service(counter_events)
.route("/api/{tail:.*}", leptos_actix::handle_server_fns())
.leptos_routes(leptos_options.to_owned(), routes.to_owned(), |cx| view! { cx, <Counters/> })
.service(Files::new("/", &site_root))
//.wrap(middleware::Compress::default())
})
.bind(&addr)?
.run()
.await
}
}
// client-only main for Trunk
else {
pub fn main() {
// isomorphic counters cannot work in a Client-Side-Rendered only
// app as a server is required to maintain state
}
}
}

View File

@@ -0,0 +1,13 @@
[package]
name = "counter_without_macros"
version = "0.1.0"
edition = "2021"
[dependencies]
leptos = { path = "../../leptos", features = ["stable"] }
console_log = "0.2"
log = "0.4"
console_error_panic_hook = "0.1.7"
[dev-dependencies]
wasm-bindgen-test = "0.3.0"

View File

@@ -0,0 +1,9 @@
[tasks.build]
command = "cargo"
args = ["+stable", "build-all-features"]
install_crate = "cargo-all-features"
[tasks.check]
command = "cargo"
args = ["+stable", "check-all-features"]
install_crate = "cargo-all-features"

View File

@@ -0,0 +1,5 @@
# Leptos Counter Example
This example is the same like the `counter` but it's written without using macros and can be build with stable Rust.
To run it, just issue the `trunk serve --open` command in the example root. This will build the app, run it, and open a new browser to serve it.

View File

@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<link data-trunk rel="rust" data-wasm-opt="z"/>
<link data-trunk rel="icon" type="image/ico" href="/public/favicon.ico"/>
</head>
<body></body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -0,0 +1,48 @@
use leptos::{ev, html::*, *};
pub struct Props {
/// The starting value for the counter
pub initial_value: i32,
/// The change that should be applied each time the button is clicked.
pub step: i32,
}
/// A simple counter view.
pub fn view(cx: Scope, props: Props) -> impl IntoView {
let Props {
initial_value,
step,
} = props;
let (value, set_value) = create_signal(cx, initial_value);
div(cx)
.child((
cx,
button(cx)
.on(ev::click, move |_| set_value.update(|value| *value = 0))
.child((cx, "Clear")),
))
.child((
cx,
button(cx)
.on(ev::click, move |_| {
set_value.update(|value| *value -= step)
})
.child((cx, "-1")),
))
.child((
cx,
span(cx)
.child((cx, "Value: "))
.child((cx, move || value.get()))
.child((cx, "!")),
))
.child((
cx,
button(cx)
.on(ev::click, move |_| {
set_value.update(|value| *value += step)
})
.child((cx, "+1")),
))
}

View File

@@ -0,0 +1,16 @@
use counter_without_macros as counter;
use leptos::*;
pub fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(|cx| {
counter::view(
cx,
counter::Props {
initial_value: 0,
step: 1,
},
)
})
}

View File

@@ -0,0 +1,58 @@
use wasm_bindgen_test::*;
wasm_bindgen_test_configure!(run_in_browser);
use counter_without_macros as counter;
use leptos::*;
use web_sys::HtmlElement;
#[wasm_bindgen_test]
fn inc() {
mount_to_body(|cx| {
counter::view(
cx,
counter::Props {
initial_value: 0,
step: 1,
},
)
});
let document = leptos::document();
let div = document.query_selector("div").unwrap().unwrap();
let clear = div
.first_child()
.unwrap()
.dyn_into::<HtmlElement>()
.unwrap();
let dec = clear
.next_sibling()
.unwrap()
.dyn_into::<HtmlElement>()
.unwrap();
let text = dec
.next_sibling()
.unwrap()
.dyn_into::<HtmlElement>()
.unwrap();
let inc = text
.next_sibling()
.unwrap()
.dyn_into::<HtmlElement>()
.unwrap();
inc.click();
inc.click();
assert_eq!(text.text_content(), Some("Value: 2!".to_string()));
dec.click();
dec.click();
dec.click();
dec.click();
assert_eq!(text.text_content(), Some("Value: -2!".to_string()));
clear.click();
assert_eq!(text.text_content(), Some("Value: 0!".to_string()));
}

View File

@@ -0,0 +1,9 @@
[tasks.build]
command = "cargo"
args = ["+nightly", "build-all-features"]
install_crate = "cargo-all-features"
[tasks.check]
command = "cargo"
args = ["+nightly", "check-all-features"]
install_crate = "cargo-all-features"

View File

@@ -0,0 +1,9 @@
# Leptos Counters Example
This example showcases a basic leptos app with many counters. It is a good example of how to setup a basic reactive app with signals and effects, and how to interact with browser events.
## Client Side Rendering
To run it as a client-side app, you can issue `trunk serve --open` in the root. This will build the entire app into one CSR bundle.
> If you don't have `trunk` installed, [click here for install instructions.](https://trunkrs.dev/)

View File

@@ -1,5 +1,6 @@
use leptos::*;
use leptos::{For, ForProps};
use leptos::{For, ForProps, *};
const MANY_COUNTERS: usize = 1000;
type CounterHolder = Vec<(usize, (ReadSignal<i32>, WriteSignal<i32>))>;
@@ -9,7 +10,7 @@ struct CounterUpdater {
}
#[component]
pub fn Counters(cx: Scope) -> web_sys::Element {
pub fn Counters(cx: Scope) -> impl IntoView {
let (next_counter_id, set_next_counter_id) = create_signal(cx, 0);
let (counters, set_counters) = create_signal::<CounterHolder>(cx, vec![]);
provide_context(cx, CounterUpdater { set_counters });
@@ -22,12 +23,14 @@ pub fn Counters(cx: Scope) -> web_sys::Element {
};
let add_many_counters = move |_| {
let mut new_counters = vec![];
for next_id in 0..1000 {
let next_id = next_counter_id();
let new_counters = (next_id..next_id + MANY_COUNTERS).map(|id| {
let signal = create_signal(cx, 0);
new_counters.push((next_id, signal));
}
set_counters.update(move |counters| counters.extend(new_counters.iter()));
(id, signal)
});
set_counters.update(move |counters| counters.extend(new_counters));
set_next_counter_id.update(|id| *id += MANY_COUNTERS);
};
let clear_counters = move |_| {
@@ -35,12 +38,12 @@ pub fn Counters(cx: Scope) -> web_sys::Element {
};
view! { cx,
<div>
<>
<button on:click=add_counter>
"Add Counter"
</button>
<button on:click=add_many_counters>
"Add 1000 Counters"
{format!("Add {MANY_COUNTERS} Counters")}
</button>
<button on:click=clear_counters>
"Clear Counters"
@@ -59,16 +62,17 @@ pub fn Counters(cx: Scope) -> web_sys::Element {
" counters."
</p>
<ul>
<For each=counters key=|counter| counter.0>{
|cx, (id, (value, set_value)): &(usize, (ReadSignal<i32>, WriteSignal<i32>))| {
view! {
cx,
<Counter id=*id value=*value set_value=*set_value/>
<For
each=counters
key=|counter| counter.0
view=move |cx, (id, (value, set_value)): (usize, (ReadSignal<i32>, WriteSignal<i32>))| {
view! { cx,
<Counter id value set_value/>
}
}
}</For>
/>
</ul>
</div>
</>
}
}
@@ -78,10 +82,12 @@ fn Counter(
id: usize,
value: ReadSignal<i32>,
set_value: WriteSignal<i32>,
) -> web_sys::Element {
let CounterUpdater { set_counters } = use_context(cx).unwrap_throw();
) -> impl IntoView {
let CounterUpdater { set_counters } = use_context(cx).unwrap();
let input = move |ev| set_value(event_target_value(&ev).parse::<i32>().unwrap_or_default());
let input = move |ev| {
set_value(event_target_value(&ev).parse::<i32>().unwrap_or_default())
};
// just an example of how a cleanup function works
// this will run when the scope is disposed, i.e., when this row is deleted
@@ -91,10 +97,10 @@ fn Counter(
<li>
<button on:click=move |_| set_value.update(move |value| *value -= 1)>"-1"</button>
<input type="text"
prop:value={move || value().to_string()}
prop:value={value}
on:input=input
/>
<span>{move || value().to_string()}</span>
<span>{value}</span>
<button on:click=move |_| set_value.update(move |value| *value += 1)>"+1"</button>
<button on:click=move |_| set_counters.update(move |counters| counters.retain(|(counter_id, _)| counter_id != &id))>"x"</button>
</li>

View File

@@ -2,7 +2,6 @@ use counters::{Counters, CountersProps};
use leptos::*;
fn main() {
console_error_panic_hook::set_once();
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(|cx| view! { cx, <Counters/> })

Some files were not shown because too many files have changed in this diff Show More