Replace Command with a new Task API with chain support
This commit is contained in:
parent
e6d0b3bda5
commit
a25b1af456
74 changed files with 1351 additions and 1767 deletions
|
|
@ -2,7 +2,7 @@
|
|||
use crate::core::text;
|
||||
use crate::core::window;
|
||||
use crate::core::{Element, Renderer};
|
||||
use crate::Command;
|
||||
use crate::Task;
|
||||
|
||||
/// The core of a user interface for a multi-window application following The Elm Architecture.
|
||||
pub trait Program: Sized {
|
||||
|
|
@ -21,9 +21,9 @@ pub trait Program: Sized {
|
|||
/// produced by either user interactions or commands, will be handled by
|
||||
/// this method.
|
||||
///
|
||||
/// Any [`Command`] returned will be executed immediately in the
|
||||
/// background by shells.
|
||||
fn update(&mut self, message: Self::Message) -> Command<Self::Message>;
|
||||
/// Any [`Task`] returned will be executed immediately in the background by the
|
||||
/// runtime.
|
||||
fn update(&mut self, message: Self::Message) -> Task<Self::Message>;
|
||||
|
||||
/// Returns the widgets to display in the [`Program`] for the `window`.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::core::renderer;
|
|||
use crate::core::widget::operation::{self, Operation};
|
||||
use crate::core::{Clipboard, Size};
|
||||
use crate::user_interface::{self, UserInterface};
|
||||
use crate::{Command, Debug, Program};
|
||||
use crate::{Debug, Program, Task};
|
||||
|
||||
/// The execution state of a multi-window [`Program`]. It leverages caching, event
|
||||
/// processing, and rendering primitive storage.
|
||||
|
|
@ -85,7 +85,7 @@ where
|
|||
/// the widgets of the linked [`Program`] if necessary.
|
||||
///
|
||||
/// Returns a list containing the instances of [`Event`] that were not
|
||||
/// captured by any widget, and the [`Command`] obtained from [`Program`]
|
||||
/// captured by any widget, and the [`Task`] obtained from [`Program`]
|
||||
/// after updating it, only if an update was necessary.
|
||||
pub fn update(
|
||||
&mut self,
|
||||
|
|
@ -96,7 +96,7 @@ where
|
|||
style: &renderer::Style,
|
||||
clipboard: &mut dyn Clipboard,
|
||||
debug: &mut Debug,
|
||||
) -> (Vec<Event>, Option<Command<P::Message>>) {
|
||||
) -> (Vec<Event>, Option<Task<P::Message>>) {
|
||||
let mut user_interfaces = build_user_interfaces(
|
||||
&self.program,
|
||||
self.caches.take().unwrap(),
|
||||
|
|
@ -163,14 +163,14 @@ where
|
|||
|
||||
drop(user_interfaces);
|
||||
|
||||
let commands = Command::batch(messages.into_iter().map(|msg| {
|
||||
let commands = Task::batch(messages.into_iter().map(|msg| {
|
||||
debug.log_message(&msg);
|
||||
|
||||
debug.update_started();
|
||||
let command = self.program.update(msg);
|
||||
let task = self.program.update(msg);
|
||||
debug.update_finished();
|
||||
|
||||
command
|
||||
task
|
||||
}));
|
||||
|
||||
let mut user_interfaces = build_user_interfaces(
|
||||
|
|
@ -205,7 +205,7 @@ where
|
|||
pub fn operate(
|
||||
&mut self,
|
||||
renderer: &mut P::Renderer,
|
||||
operations: impl Iterator<Item = Box<dyn Operation<P::Message>>>,
|
||||
operations: impl Iterator<Item = Box<dyn Operation<()>>>,
|
||||
bounds: Size,
|
||||
debug: &mut Debug,
|
||||
) {
|
||||
|
|
@ -227,9 +227,7 @@ where
|
|||
|
||||
match operation.finish() {
|
||||
operation::Outcome::None => {}
|
||||
operation::Outcome::Some(message) => {
|
||||
self.queued_messages.push(message);
|
||||
}
|
||||
operation::Outcome::Some(()) => {}
|
||||
operation::Outcome::Chain(next) => {
|
||||
current_operation = Some(next);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue