refactor: replace load method with reload, returning Command

This commit is contained in:
Michael Aaron Murphy 2024-01-16 17:04:55 +01:00 committed by Michael Murphy
parent c6bf1525d8
commit 3787bf8cbc
7 changed files with 25 additions and 38 deletions

View file

@ -3,7 +3,7 @@
use crate::section::{self, Section};
use crate::{Content, Info, Page};
use cosmic::iced_runtime::command::{Action, Command};
use cosmic::iced_runtime::command::Command;
use cosmic::Element;
use regex::Regex;
use slotmap::{SecondaryMap, SlotMap, SparseSecondaryMap};
@ -159,14 +159,12 @@ impl<Message: 'static> Binder<Message> {
}
/// Calls a page's load function to refresh its data.
pub fn page_reload(&mut self, id: crate::Entity) -> Option<Command<Message>> {
if let Some(page) = self.page.get(id) {
if let Some(future) = page.load(id) {
return Some(Command::single(Action::Future(future)));
}
pub fn page_reload(&mut self, id: crate::Entity) -> Command<Message> {
if let Some(page) = self.page.get_mut(id) {
return page.reload(id);
}
None
Command::none()
}
#[must_use]

View file

@ -14,7 +14,7 @@ pub use section::Section;
use derive_setters::Setters;
use slotmap::SlotMap;
use std::{borrow::Cow, future::Future, pin::Pin};
use std::borrow::Cow;
slotmap::new_key_type! {
/// The unique ID of a page.
@ -24,9 +24,6 @@ slotmap::new_key_type! {
/// A collection of sections which a page may be comprised of.
pub type Content = Vec<section::Entity>;
/// A request by a page to run a command in the background.
pub type Task<Message> = Pin<Box<dyn Future<Output = Message> + Send>>;
pub trait Page<Message: 'static>: Downcast {
/// Information about the page
fn info(&self) -> Info;
@ -51,8 +48,8 @@ pub trait Page<Message: 'static>: Downcast {
#[must_use]
#[allow(unused)]
fn load(&self, page: crate::Entity) -> Option<crate::Task<Message>> {
None
fn reload(&mut self, page: crate::Entity) -> Command<Message> {
Command::none()
}
/// Emit a command when the page is left