-
Notifications
You must be signed in to change notification settings - Fork 34
Add storage hook #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add storage hook #17
Changes from 72 commits
Commits
Show all changes
117 commits
Select commit
Hold shift + click to select a range
567ae82
add storage hook
ealmloff 0c3f4bd
save work
esimkowitz 5ae1da2
swap back to async_broadcast
esimkowitz e963c80
remove comments
esimkowitz 0e69cd5
save work
esimkowitz 0616011
save work
esimkowitz 856c860
it works!
esimkowitz f0e7fdc
remove unnecessary dependency
esimkowitz 48e7b4d
remove unused imports
esimkowitz 0157bd1
add localstorage
esimkowitz d957fb3
add unsubscribe
esimkowitz 1778184
Merge branch 'storage-v4' into storage-v5
esimkowitz 0d015b4
save work
esimkowitz f6d7e29
change name
esimkowitz 68dcbfb
Break subscriber out
esimkowitz 321ff7b
break out subscribe
esimkowitz 06d1576
update example
esimkowitz 577a41a
small refactoring
esimkowitz 59df763
update sample
esimkowitz 3bb8937
change UsePersistent to UseStorageEntry, use everywhere
esimkowitz d966cef
more refactoring
esimkowitz 84e4c2f
Remove custom UseStorageEntryRef
esimkowitz 2e33853
remove StorageEntryMut in favor of with_mut
esimkowitz 8ba7c46
add clone and copy derives
esimkowitz 4a84603
save work
esimkowitz 84c47f2
potential signal-centric alternative
esimkowitz e72df4e
save
esimkowitz e0a929d
it works!
esimkowitz 856a860
fix persistence
esimkowitz 1d7884f
use_effect instead of use_subscribe
esimkowitz eaa787c
fix use_effect
esimkowitz 2f83149
Merge pull request #1 from esimkowitz/storage-v4.1
esimkowitz 1e4b0e6
working on ssr
esimkowitz d6ae6e9
refactoring for devex
esimkowitz f4299c9
add comments
esimkowitz cb703af
add more comments
esimkowitz 32eeac7
format
esimkowitz d40b47c
remove unnecessary constraints
esimkowitz 640d45a
change name
esimkowitz 5579de2
fix ssr
esimkowitz 7658e0a
expose getters for channel and key in storageentry
esimkowitz b4f0c56
format
esimkowitz 65d3c4a
update to use watch channels
esimkowitz 483ec12
fix cargo
esimkowitz f7b5fb0
simplify synced save
esimkowitz 07d2c93
add more comments, fix unsubscribe
esimkowitz 4b4c0f2
split storage desktop and web examples
esimkowitz 5a95fc0
Merge pull request #2 from esimkowitz/storage-v4.2
esimkowitz 9917de4
remove semicolon
esimkowitz 97d84e6
typo
esimkowitz 25300cb
remove dashmap due to wasm compatibility issues
esimkowitz 0470435
add comments
esimkowitz 8b74f37
adding filesystem and memory stores
esimkowitz 5de9137
more comments
esimkowitz 270e5d5
Updating storage desktop example to add new window
esimkowitz ab764a8
Remove notify crate
esimkowitz e5aaf73
fix typo
esimkowitz dcff702
Merge pull request #3 from esimkowitz/storage-v4.3
esimkowitz 1c7e1f6
add more comments
esimkowitz fcd4abc
make log info into trace
esimkowitz 474433c
fix memory map
esimkowitz 016c925
Update in-memory to use Any instead of serialize
esimkowitz ca9b45a
Merge pull request #1 from esimkowitz/storage-v4
ealmloff a35bdc1
add clone bound to the web storage subscribe method
ealmloff 48f5737
fix clippy
ealmloff 69c6c0a
add non-hook versions of storage
ealmloff cb1eecf
add new_ prefix to the non-hook storage functions
ealmloff 2b2e9a9
fix storage example import
ealmloff c29a1c3
add use_storage example
ealmloff f0ae975
add example to new_storage
ealmloff 1fb405c
fix some lints
ealmloff 7a99a3e
remove storage from the default features
ealmloff 22c03cb
update some out of date readmes
ealmloff 178aa78
export new_ variants of hooks
ealmloff 2e2c00d
log serialization errors
ealmloff 72d2346
fix formatting
ealmloff 9d79bb9
add storage to the tested features
ealmloff 0edb165
fix dioxus storage tests
ealmloff 63fe35e
only enable desktop features for clippy
ealmloff 9e4e53b
fix formatting
ealmloff cf79ae7
feat: Dioxus 0.5 support
marc2332 137b414
updated dioxus
marc2332 cde6452
fix use_clipboard
marc2332 191edf0
fix use_clipboard again
marc2332 73e2d0c
better error handling of use_clipboard
marc2332 d084129
fmt
marc2332 7b4dbe3
fix
marc2332 6791b1d
fixing it blindly
marc2332 b79c38d
chore: Bump dx
marc2332 a5ebe58
Remove unwrap
marc2332 791a21f
chore: Fixes
marc2332 074c27a
derive copy and clean up
marc2332 ce5ea55
fix
marc2332 4424071
fix
marc2332 1b35f9d
empty
marc2332 42adeb4
fix use_geolocation
marc2332 f330cdb
fix
marc2332 2e111cd
bump dx
marc2332 e8d3b67
bump dx
marc2332 ddcb7a1
Merge branch 'master' into feat/dioxus-0.5
marc2332 569e9b2
fixes
marc2332 8279239
bump dx
marc2332 0fe58a6
bump dx
marc2332 4d8ae33
0.5
marc2332 33f6fce
bump dx, fmt, clippy
marc2332 fd64567
nuke use_rw and fix use_geolocation
marc2332 bc29d7c
clippy
marc2332 a07270f
clippy
marc2332 e1ad3ab
Merge branch 'master' into storage
ealmloff 0fca567
move storage into the workspace
ealmloff eca4ad0
Merge branch 'pr/marc2332/23' into storage
ealmloff e3ad85b
revert channel changes
ealmloff a8e4f99
fix dioxus storage
ealmloff a94f61b
Merge branch 'master' into storage
ealmloff 3a27bdf
fix formatting
ealmloff 25e6b2a
address comments
ealmloff fa7871c
remove unnessicary lock
ealmloff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,12 @@ | ||
[package] | ||
name = "storage-desktop" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
dioxus-std = { path="../../", features = ["storage"] } | ||
dioxus = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "647815fa6f6db2304cda5bd36c78b4f8b0379f39" } | ||
dioxus-desktop = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "647815fa6f6db2304cda5bd36c78b4f8b0379f39" } | ||
dioxus-router = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "647815fa6f6db2304cda5bd36c78b4f8b0379f39" } | ||
log = "0.4.6" | ||
|
This file contains hidden or 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 @@ | ||
# use_persistant | ||
ealmloff marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
Learn how to use `use_persistant`. | ||
|
||
Run: | ||
|
||
```dioxus serve``` |
This file contains hidden or 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,113 @@ | ||
use dioxus::prelude::*; | ||
use dioxus_router::prelude::*; | ||
use dioxus_std::storage::*; | ||
|
||
fn main() { | ||
match log::set_boxed_logger(Box::new(simple_logger::SimpleLogger)) { | ||
Ok(_) => log::set_max_level(log::LevelFilter::Info), | ||
Err(e) => panic!("Failed to initialize logger: {}", e), | ||
} | ||
dioxus_std::storage::set_dir!(); | ||
dioxus_desktop::launch(App); | ||
} | ||
|
||
#[component] | ||
fn App(cx: Scope) -> Element { | ||
render! { | ||
Router::<Route> {} | ||
} | ||
} | ||
|
||
#[derive(Routable, Clone)] | ||
#[rustfmt::skip] | ||
enum Route { | ||
#[layout(Footer)] | ||
#[route("/")] | ||
Page1 {}, | ||
#[route("/page2")] | ||
Page2 {}, | ||
} | ||
|
||
#[component] | ||
fn Footer(cx: Scope) -> Element { | ||
let window = dioxus_desktop::use_window(cx); | ||
|
||
render! { | ||
div { | ||
Outlet::<Route> { } | ||
|
||
p { | ||
"----" | ||
} | ||
|
||
div { | ||
button { | ||
onclick: move |_| { | ||
let dom = VirtualDom::new(App); | ||
window.new_window(dom, Default::default()); | ||
}, | ||
"New Window" | ||
} | ||
} | ||
|
||
nav { | ||
ul { | ||
li { Link { to: Route::Page1 {}, "Page1" } } | ||
li { Link { to: Route::Page2 {}, "Page2" } } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[component] | ||
fn Page1(cx: Scope) -> Element { | ||
render!("Home") | ||
} | ||
|
||
#[component] | ||
fn Page2(cx: Scope) -> Element { | ||
let count_session = use_singleton_persistent(cx, || 0); | ||
let count_local = use_synced_storage::<LocalStorage, i32>(cx, "synced".to_string(), || 0); | ||
|
||
render!( | ||
div { | ||
button { | ||
onclick: move |_| { | ||
*count_session.write() += 1; | ||
}, | ||
"Click me!" | ||
}, | ||
"I persist for the current session. Clicked {count_session} times" | ||
} | ||
div { | ||
button { | ||
onclick: move |_| { | ||
*count_local.write() += 1; | ||
}, | ||
"Click me!" | ||
}, | ||
"I persist across all sessions. Clicked {count_local} times" | ||
} | ||
) | ||
} | ||
|
||
mod simple_logger { | ||
use log::{Metadata, Record}; | ||
|
||
pub struct SimpleLogger; | ||
|
||
impl log::Log for SimpleLogger { | ||
fn enabled(&self, metadata: &Metadata) -> bool { | ||
metadata.level() <= log::max_level() | ||
} | ||
|
||
fn log(&self, record: &Record) { | ||
if self.enabled(record.metadata()) { | ||
println!("{} - {}", record.level(), record.args()); | ||
} | ||
} | ||
|
||
fn flush(&self) {} | ||
} | ||
} |
This file contains hidden or 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,15 @@ | ||
[package] | ||
name = "storage-web" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
dioxus-std = { path="../../", features = ["storage"] } | ||
dioxus = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "647815fa6f6db2304cda5bd36c78b4f8b0379f39" } | ||
dioxus-web = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "647815fa6f6db2304cda5bd36c78b4f8b0379f39" } | ||
dioxus-router = { git = "https://github.com/DioxusLabs/dioxus.git", rev = "647815fa6f6db2304cda5bd36c78b4f8b0379f39" } | ||
log = "0.4.6" | ||
|
||
# WebAssembly Debug | ||
wasm-logger = "0.2.0" | ||
console_error_panic_hook = "0.1.7" |
This file contains hidden or 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 @@ | ||
# use_persistant | ||
|
||
Learn how to use `use_persistant`. | ||
|
||
Run: | ||
|
||
```dioxus serve``` |
This file contains hidden or 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,79 @@ | ||
use dioxus::prelude::*; | ||
use dioxus_router::prelude::*; | ||
use dioxus_std::storage::*; | ||
|
||
fn main() { | ||
// init debug tool for WebAssembly | ||
wasm_logger::init(wasm_logger::Config::default()); | ||
console_error_panic_hook::set_once(); | ||
dioxus_web::launch(App); | ||
} | ||
|
||
#[component] | ||
fn App(cx: Scope) -> Element { | ||
render! { | ||
Router::<Route> {} | ||
} | ||
} | ||
|
||
#[derive(Routable, Clone)] | ||
#[rustfmt::skip] | ||
enum Route { | ||
#[layout(Footer)] | ||
#[route("/")] | ||
Page1 {}, | ||
#[route("/page2")] | ||
Page2 {}, | ||
} | ||
|
||
#[component] | ||
fn Footer(cx: Scope) -> Element { | ||
render! { | ||
div { | ||
Outlet::<Route> { } | ||
|
||
p { | ||
"----" | ||
} | ||
|
||
nav { | ||
ul { | ||
li { Link { to: Route::Page1 {}, "Page1" } } | ||
li { Link { to: Route::Page2 {}, "Page2" } } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[component] | ||
fn Page1(cx: Scope) -> Element { | ||
render!("Home") | ||
} | ||
|
||
#[component] | ||
fn Page2(cx: Scope) -> Element { | ||
let count_session = use_singleton_persistent(cx, || 0); | ||
let count_local = use_synced_storage::<LocalStorage, i32>(cx, "synced".to_string(), || 0); | ||
|
||
render!( | ||
div { | ||
button { | ||
onclick: move |_| { | ||
*count_session.write() += 1; | ||
}, | ||
"Click me!" | ||
}, | ||
"I persist for the current session. Clicked {count_session} times" | ||
} | ||
div { | ||
button { | ||
onclick: move |_| { | ||
*count_local.write() += 1; | ||
}, | ||
"Click me!" | ||
}, | ||
"I persist across all sessions. Clicked {count_local} times" | ||
} | ||
) | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.