Skip to content

Commit

Permalink
fmt doc coment with new moonbit; add in README
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Dec 6, 2024
1 parent 1e90c9f commit 69e4fa8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions moon.mod.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/main/counter.mbt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/main/main.mbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
///|
let app_store_key : String = "mbt-workflow"

///|
fn view(
store : Store
) -> @respo_node.RespoNode[ActionOp]!@respo_node.RespoCommonError {
Expand All @@ -15,6 +17,7 @@ fn view(
)
}

///|
fn main {
let window = @dom_ffi.window()
let mount_target = window
Expand Down
12 changes: 11 additions & 1 deletion src/main/store.mbt
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
///|
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
content : String
time : Double
} derive(Default, Eq, Hash, ToJson, @json.FromJson)

///|
enum IndentOp {
Noop
}

///|
enum ActionOp {
Noop
StatesChange(@respo.RespoUpdateState)
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -62,6 +71,7 @@ fn update(self : Store, op : ActionOp) -> Unit {
}
}

///|
fn to_string(self : Store) -> String {
self.to_json().stringify(indent=2)
}

0 comments on commit 69e4fa8

Please sign in to comment.