Skip to content

Commit 2bc2260

Browse files
committed
renamed, and made the app better! also, tests work (tediously)
1 parent bdda727 commit 2bc2260

File tree

43 files changed

+751
-584
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+751
-584
lines changed

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result<Command> {
10721072
"echo",
10731073
"fibonacci",
10741074
"file-transfer",
1075-
"framework-process"
1075+
"hyperapp-todo"
10761076
])
10771077
.default_value("chat")
10781078
)

src/new/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub enum Template {
2323
Echo,
2424
Fibonacci,
2525
FileTransfer,
26-
FrameworkProcess,
26+
HyperappTodo,
2727
}
2828

2929
impl Language {
@@ -45,7 +45,7 @@ impl Template {
4545
Template::Echo => "echo",
4646
Template::Fibonacci => "fibonacci",
4747
Template::FileTransfer => "file-transfer",
48-
Template::FrameworkProcess => "framework-process",
48+
Template::HyperappTodo => "hyperapp-todo",
4949
}
5050
.to_string()
5151
}
@@ -70,8 +70,8 @@ impl From<&String> for Template {
7070
"echo" => Template::Echo,
7171
"fibonacci" => Template::Fibonacci,
7272
"file-transfer" => Template::FileTransfer,
73-
"framework-process" => Template::FrameworkProcess,
74-
_ => panic!("kit: template must be 'blank', 'chat', 'echo', 'fibonacci', 'file-transfer', or 'framework-process'; not '{s}'"),
73+
"hyperapp-todo" => Template::HyperappTodo,
74+
_ => panic!("kit: template must be 'blank', 'chat', 'echo', 'fibonacci', 'file-transfer', or 'hyperapp-todo'; not '{s}'"),
7575
}
7676
}
7777
}

src/new/templates/rust/ui/framework-process/framework-process/src/lib.rs

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/new/templates/rust/ui/framework-process/test/framework-process-test/framework-process-test/Cargo.toml

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/new/templates/rust/ui/framework-process/test/framework-process-test/framework-process-test/src/lib.rs

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/new/templates/rust/ui/framework-process/test/framework-process-test/pkg/manifest.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/new/templates/rust/ui/framework-process/.gitignore renamed to src/new/templates/rust/ui/hyperapp-todo/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
api
2+
!test/hyperapp-todo-test/api
23
*swp
34
**/target
45
pkg/*.wasm

src/new/templates/rust/ui/framework-process/Cargo.toml renamed to src/new/templates/rust/ui/hyperapp-todo/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ panic = "abort"
55

66
[workspace]
77
members = [
8-
"framework-process",
9-
"test/framework-process-test/framework-process-test",
8+
"hyperapp-todo",
9+
"test/hyperapp-todo-test/hyperapp-todo-test",
1010
]
1111
resolver = "2"

src/new/templates/rust/ui/framework-process/framework-process/Cargo.toml renamed to src/new/templates/rust/ui/hyperapp-todo/hyperapp-todo/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ process_macros = "0.1"
44
rmp-serde = "1.3.0"
55
serde_json = "1.0"
66
wit-bindgen = "0.36.0"
7+
uuid = "1.4.1"
78

89

910

@@ -27,7 +28,7 @@ crate-type = ["cdylib"]
2728

2829
[package]
2930
edition = "2021"
30-
name = "framework-process"
31+
name = "hyperapp-todo"
3132
version = "0.1.0"
3233

3334
[package.metadata.component]
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
use hyperprocess_macro::hyperprocess;
2+
use serde::{Deserialize, Serialize};
3+
use uuid::Uuid; // Keep Uuid
4+
5+
// --- Todo Item ---
6+
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
7+
pub struct TodoItem {
8+
id: String,
9+
text: String,
10+
completed: bool,
11+
}
12+
13+
// --- State ---
14+
// Add Clone for potential use in export/internal logic if needed.
15+
#[derive(PartialEq, Clone, Default, Debug, Serialize, Deserialize)]
16+
pub struct HyperappTodoState {
17+
tasks: Vec<TodoItem>,
18+
}
19+
20+
// --- Hyperware Process ---
21+
#[hyperprocess(
22+
name = "hyperapp-todo",
23+
ui = Some(HttpBindingConfig::default()),
24+
endpoints = vec![
25+
Binding::Http {
26+
path: "/api",
27+
config: HttpBindingConfig::new(false, false, false, None),
28+
},
29+
Binding::Ws {
30+
path: "/ws",
31+
config: WsBindingConfig::new(false, false, false),
32+
}
33+
],
34+
save_config = SaveOptions::EveryMessage,
35+
wit_world = "hyperapp-todo-template-dot-os-v0"
36+
)]
37+
38+
// --- Hyperware Process API definitions ---
39+
impl HyperappTodoState {
40+
#[init]
41+
async fn initialize(&mut self) {
42+
println!("Initializing todo list state");
43+
self.tasks = Vec::new();
44+
}
45+
46+
// Add a new task
47+
#[http]
48+
async fn add_task(&mut self, text: String) -> Result<TodoItem, String> {
49+
if text.trim().is_empty() {
50+
return Err("Task text cannot be empty".to_string());
51+
}
52+
let new_task = TodoItem {
53+
id: Uuid::new_v4().to_string(),
54+
text,
55+
completed: false,
56+
};
57+
self.tasks.push(new_task.clone());
58+
println!("Added task: {:?}", new_task);
59+
Ok(new_task)
60+
}
61+
62+
// Get all tasks
63+
#[http]
64+
async fn get_tasks(&self, request: String) -> Result<Vec<TodoItem>, String> {
65+
println!("Request: {:?}", request);
66+
println!("Fetching tasks");
67+
Ok(self.tasks.clone())
68+
}
69+
70+
71+
// Toggle completion status of a task
72+
#[http]
73+
async fn toggle_task(&mut self, id: String) -> Result<TodoItem, String> {
74+
if let Some(task) = self.tasks.iter_mut().find(|t| t.id == id) {
75+
task.completed = !task.completed;
76+
println!("Toggled task {:?}: completed={}", task.id, task.completed);
77+
Ok(task.clone())
78+
} else {
79+
Err(format!("Task with ID {} not found", id))
80+
}
81+
}
82+
83+
// Export the current state (all tasks) as JSON bytes
84+
#[local]
85+
#[remote]
86+
async fn export_state(&self) -> Result<HyperappTodoState, String> {
87+
println!("Exporting tasks request received");
88+
// Return the state directly instead of serializing it
89+
Ok(self.clone())
90+
}
91+
92+
// Import tasks from JSON bytes, replacing the current tasks
93+
#[local]
94+
async fn import_state(&mut self, data: Vec<u8>) -> Result<bool, String> {
95+
println!("Importing tasks request received");
96+
// Deserialize the data into the state struct using from_slice for Vec<u8>
97+
let imported_state: HyperappTodoState = serde_json::from_slice(&data)
98+
.map_err(|e| format!("Failed to deserialize state data: {}", e))?;
99+
// Replace the current tasks with the imported ones
100+
self.tasks = imported_state.tasks;
101+
println!("Tasks imported successfully");
102+
Ok(true)
103+
}
104+
105+
}

0 commit comments

Comments
 (0)