Skip to content

Commit

Permalink
Merge pull request #302 from redbadger/viktor/cat-facts-on-new-kv
Browse files Browse the repository at this point in the history
[Blocked] Migrate cat_facts to new crux_kv.
  • Loading branch information
charypar authored Jan 22, 2025
2 parents 81dddbb + 93ae5d1 commit fa3b105
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 48 deletions.
68 changes: 38 additions & 30 deletions examples/cat_facts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions examples/cat_facts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ rust-version = "1.66"

[workspace.dependencies]
anyhow = "1.0.95"
# crux_core = { path = "../../crux_core" }
# crux_http = { path = "../../crux_http" }
# crux_kv = { path = "../../crux_kv" }
# crux_platform = { path = "../../crux_platform" }
# crux_time = { path = "../../crux_time", features = ["chrono"] }
crux_core = "0.11.0"
crux_http = "0.11.0"
crux_kv = "0.6.0"
crux_platform = "0.3.0"
crux_time = { version = "0.8.0", features = ["chrono"] }
crux_core = { path = "../../crux_core" }
crux_http = { path = "../../crux_http" }
crux_kv = { path = "../../crux_kv" }
crux_platform = { path = "../../crux_platform" }
crux_time = { path = "../../crux_time", features = ["chrono"] }
# crux_core = "0.11.0"
# crux_http = "0.11.0"
# crux_kv = "0.6.0"
# crux_platform = "0.3.0"
# crux_time = { version = "0.8.0", features = ["chrono"] }
serde = "1.0.217"

[workspace.metadata.bin]
Expand Down
18 changes: 10 additions & 8 deletions examples/cat_facts/shared/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crux_core::{
Capability, Command,
};
use crux_http::Http;
use crux_kv::{error::KeyValueError, KeyValue};
use crux_kv::{command::KeyValue as key_value, error::KeyValueError, KeyValue};
use crux_platform::Platform;
use crux_time::{Time, TimeResponse};

Expand Down Expand Up @@ -168,9 +168,11 @@ impl App for CatFacts {
model.cat_image = Some(response.take_body().unwrap());

let bytes = serde_json::to_vec(&model).unwrap();
caps.key_value.set(KEY.to_string(), bytes, |_| Event::None);

return render::render();
return Command::all([
key_value::set(KEY, bytes).then_send(|_| Event::None),
render::render(),
]);
}
Event::SetFact(Err(_)) | Event::SetImage(Err(_)) => {
// TODO: Display an error
Expand All @@ -180,14 +182,14 @@ impl App for CatFacts {
model.time = Some(time.to_rfc3339_opts(chrono::SecondsFormat::Secs, true));

let bytes = serde_json::to_vec(&model).unwrap();
caps.key_value.set(KEY.to_string(), bytes, |_| Event::None);

return render::render();
return Command::all([
key_value::set(KEY, bytes).then_send(|_| Event::None),
render::render(),
]);
}
Event::CurrentTime(_) => panic!("Unexpected time response"),
Event::Restore => {
caps.key_value.get(KEY.to_string(), Event::SetState);
}
Event::Restore => return key_value::get(KEY).then_send(Event::SetState),
Event::SetState(Ok(Some(value))) => {
if let Ok(m) = serde_json::from_slice::<Model>(&value) {
*model = m;
Expand Down

0 comments on commit fa3b105

Please sign in to comment.