-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
605 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# use_web_lock | ||
|
||
<!-- cmdrun python3 ../extract_doc_comment.py use_web_lock use_web_lock --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "use_web_lock" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
gloo-timers = { version = "0.3", features = ["futures"] } | ||
leptos = { version = "0.6", features = ["nightly", "csr"] } | ||
console_error_panic_hook = "0.1" | ||
console_log = "1" | ||
log = "0.4" | ||
leptos-use = { path = "../..", features = ["use_web_lock", "docs"] } | ||
web-sys = { version = "0.3", features = ["Lock"] } | ||
|
||
[dev-dependencies] | ||
wasm-bindgen = "0.2" | ||
wasm-bindgen-test = "0.3.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
A simple example for `use_web_lock`. | ||
|
||
If you don't have it installed already, install [Trunk](https://trunkrs.dev/) and [Tailwind](https://tailwindcss.com/docs/installation) | ||
as well as the nightly toolchain for Rust and the wasm32-unknown-unknown target: | ||
|
||
```bash | ||
cargo install trunk | ||
npm install -D tailwindcss @tailwindcss/forms | ||
rustup toolchain install nightly | ||
rustup target add wasm32-unknown-unknown | ||
``` | ||
|
||
Then, open two terminals. In the first one, run: | ||
|
||
``` | ||
npx tailwindcss -i ./input.css -o ./style/output.css --watch | ||
``` | ||
|
||
In the second one, run: | ||
|
||
```bash | ||
trunk serve --open | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[build] | ||
public_url = "/demo/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<link data-trunk rel="css" href="style/output.css"> | ||
</head> | ||
<body></body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[toolchain] | ||
channel = "nightly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use gloo_timers::future::sleep; | ||
use leptos::*; | ||
use leptos_use::docs::demo_or_body; | ||
use leptos_use::use_web_lock; | ||
use std::time::Duration; | ||
|
||
async fn my_process(_lock: web_sys::Lock) -> i32 { | ||
sleep(Duration::from_millis(2000)).await; | ||
|
||
42 | ||
} | ||
|
||
#[component] | ||
fn Demo() -> impl IntoView { | ||
let (res, set_res) = create_signal("Not started yet".to_string()); | ||
|
||
let on_click = move |_| { | ||
set_res.set("Running...".to_string()); | ||
|
||
spawn_local(async move { | ||
let res = use_web_lock("my_lock", my_process).await; | ||
|
||
match res { | ||
Ok(res) => { | ||
set_res.set(format!("Result: {}", res)); | ||
} | ||
Err(e) => { | ||
set_res.set(format!("Error: {:?}", e)); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
view! { | ||
<button on:click=on_click>Run locked task</button> | ||
<p>{res}</p> | ||
} | ||
} | ||
|
||
fn main() { | ||
_ = console_log::init_with_level(log::Level::Debug); | ||
console_error_panic_hook::set_once(); | ||
|
||
mount_to(demo_or_body(), || { | ||
view! { <Demo/> } | ||
}) | ||
} |
Oops, something went wrong.