Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert ui state as resource and system to react to changes #71

Closed
JunichiSugiura opened this issue Sep 3, 2022 · 0 comments · Fixed by #73
Closed

Insert ui state as resource and system to react to changes #71

JunichiSugiura opened this issue Sep 3, 2022 · 0 comments · Fixed by #73
Assignees
Labels
enhancement New feature or request

Comments

@JunichiSugiura
Copy link
Member

JunichiSugiura commented Sep 3, 2022

Criteria

  • insert each ui state as individual resource
  • automatically trigger rerender when ui state resources are changed

Old

fn update_todo_list(
    mut events: EventReader<NewTodoList>,
    mut ui_state: EventWriter<UiState>,
) {
    for e in events.iter() {
        ui_state.send(UiState::TodoList(e.todo_list.clone()));
    }
}

New

fn update_todo_list(
    mut events: EventReader<NewTodoList>,
    mut todo_list: ResMut<TodoList>,
) {
    for e in events.iter() {
        *todo_list = e.todo_list.clone();
    }
}

// generated
fn dispatch_todo_list(
    todo_list: Res<Vec<UiTodo>>,
    mut ui_state: EventWriter<UiState>,
) {
    if todo_list.is_changed() {
        ui_state.send(UiState::TodoList(todo_list.clone()));
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant