From 69e4fa8e020809f4bf3bac612436de81a6f873c8 Mon Sep 17 00:00:00 2001 From: tiye Date: Sat, 7 Dec 2024 02:06:36 +0800 Subject: [PATCH] fmt doc coment with new moonbit; add in README --- README.md | 13 ++++++++++++- moon.mod.json | 4 ++-- src/main/counter.mbt | 2 ++ src/main/main.mbt | 3 +++ src/main/store.mbt | 12 +++++++++++- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2e8e436..fe30425 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,18 @@ ## Boilerplate project for Respo ```bash -yarn build +moon build --target js --debug --watch + +yarn +yarn vite +``` + +To build the project, run: + +```bash +moon build --target js +yarn +yarn vite build --base ./ ``` ## License diff --git a/moon.mod.json b/moon.mod.json index 1bbf170..03e7322 100644 --- a/moon.mod.json +++ b/moon.mod.json @@ -1,8 +1,8 @@ { - "name": "tiye/respo-workflow", + "name": "respo/app", "version": "0.1.0", "deps": { - "tiye/respo": "0.0.17", + "tiye/respo": "0.0.19", "tiye/dom-ffi": "0.0.6" }, "readme": "README.md", diff --git a/src/main/counter.mbt b/src/main/counter.mbt index dec529d..85772c2 100644 --- a/src/main/counter.mbt +++ b/src/main/counter.mbt @@ -1,8 +1,10 @@ // // #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, RespoState)] +///| struct MainState { counted : Int } derive(Default, ToJson, @json.FromJson) +///| fn comp_counter( states : @respo.RespoStatesTree, global_counted : Int diff --git a/src/main/main.mbt b/src/main/main.mbt index dfaecd9..1681fa5 100644 --- a/src/main/main.mbt +++ b/src/main/main.mbt @@ -1,5 +1,7 @@ +///| let app_store_key : String = "mbt-workflow" +///| fn view( store : Store ) -> @respo_node.RespoNode[ActionOp]!@respo_node.RespoCommonError { @@ -15,6 +17,7 @@ fn view( ) } +///| fn main { let window = @dom_ffi.window() let mount_target = window diff --git a/src/main/store.mbt b/src/main/store.mbt index e0a700f..9541831 100644 --- a/src/main/store.mbt +++ b/src/main/store.mbt @@ -1,13 +1,16 @@ +///| struct Store { mut counted : Int tasks : Array[Task] states : @respo.RespoStatesTree } derive(ToJson, @json.FromJson) +///| fn Store::default() -> Store { { counted: 0, tasks: [], states: @respo.RespoStatesTree::default() } } +///| struct Task { id : String done : Bool @@ -15,10 +18,12 @@ struct Task { time : Double } derive(Default, Eq, Hash, ToJson, @json.FromJson) +///| enum IndentOp { Noop } +///| enum ActionOp { Noop StatesChange(@respo.RespoUpdateState) @@ -28,14 +33,17 @@ enum ActionOp { IncTwice } +///| fn ActionOp::default() -> ActionOp { Noop } +///| impl @respo_node.RespoAction for ActionOp with build_states_action(cursor, a) { ActionOp::StatesChange({ cursor, data: Some(a.to_json()) }) } +///| fn ActionOp::to_string(self : ActionOp) -> String { match self { Noop => "Noop" @@ -48,11 +56,12 @@ fn ActionOp::to_string(self : ActionOp) -> String { } } +///| fn get_states(self : Store) -> @respo.RespoStatesTree { self.states } -/// TODO mutation might break memoization infuture +///| TODO mutation might break memoization infuture fn update(self : Store, op : ActionOp) -> Unit { match op { Increment => self.counted += 1 @@ -62,6 +71,7 @@ fn update(self : Store, op : ActionOp) -> Unit { } } +///| fn to_string(self : Store) -> String { self.to_json().stringify(indent=2) }