Skip to content

Commit

Permalink
Merge branch 'main' into feat/#110-nested-subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
JunichiSugiura committed Sep 14, 2022
2 parents c18666e + 7f983f0 commit 8f656a0
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ fn Root(cx: Scope) -> Element {

## Features

#### Desktop App
### Desktop App

#### Minimum setup with component state

<details>
<summary>Code example</summary>
Expand Down Expand Up @@ -100,7 +102,14 @@ fn Root(cx: Scope) -> Element {

</details>

#### CLI App
#### Keyboard handling
- [Keyboard event](https://github.com/diptools/dip/blob/main/examples/keyboard/keyboard_event.rs)
- [Key bindings](https://github.com/diptools/dip/blob/main/examples/keyboard/bindings.rs)


### CLI App

#### CliPlugin

<details>
<summary>Code example</summary>
Expand Down Expand Up @@ -210,7 +219,9 @@ SUBCOMMANDS:
```
</details>

#### State management
### State management (Inspired by Redux)

#### UiStatePlugin, UiActionPlugin

<details>
<summary>Code example</summary>
Expand Down Expand Up @@ -241,16 +252,21 @@ fn main() {
}
// Step 1: Define UiState
// Each field represents root state. You can create multiple of them.
// This macro generates UiState enum and UiStatePlugin which will be used in step 7.
#[ui_state]
struct UiState {
name: Name,
}
// Make sure to wrap primitive types or common type such as String with named struct or enum.
// You need to distinguish types in order to query specific root state in step 4 (system).
#[derive(Clone, Debug)]
pub struct Name {
value: String,
}
// This is how you define default value for Name root state.
impl Default for Name {
fn default() -> Self {
Self {
Expand All @@ -260,20 +276,24 @@ impl Default for Name {
}
// Step 2. Define actions
// Create as many as actions with struct or enum.
#[derive(Clone, Debug)]
pub struct UpdateName {
value: String,
}
// Step 3. Implement action creators
// Each method needs to return one of actions that your defined in step 2.
// This macro derives UiActionPlugin and UiAction which will be used in step 7.
#[ui_action]
impl ActionCreator {
fn update_name(value: String) -> UpdateName {
UpdateName { value }
}
}
// Step 4. Implement systems to handle each action defined in step 2
// Step 4. Implement systems to handle each action defined in step 2.
// System is like reducer in Redux but more flexible.
fn update_name(mut events: EventReader<UpdateName>, mut name: ResMut<Name>) {
for action in events.iter() {
name.value = action.value.clone();
Expand Down Expand Up @@ -302,10 +322,6 @@ fn Root(cx: Scope) -> Element {

</details>

#### Keyboard handling
- [Keyboard event](https://github.com/diptools/dip/blob/main/examples/keyboard/keyboard_event.rs)
- [Key bindings](https://github.com/diptools/dip/blob/main/examples/keyboard/bindings.rs)

## About Bevy and Dioxus
### Bevy
[https://github.com/bevyengine/bevy](https://github.com/bevyengine/bevy)
Expand Down

0 comments on commit 8f656a0

Please sign in to comment.