From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id E0C381FF17A for ; Tue, 9 Dec 2025 19:31:07 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A4502AF1A; Tue, 9 Dec 2025 19:31:47 +0100 (CET) Message-ID: Date: Tue, 9 Dec 2025 19:31:14 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta To: Yew framework devel list at Proxmox , Dietmar Maurer References: <20251209131159.4027954-1-dietmar@proxmox.com> Content-Language: en-US From: Thomas Lamprecht In-Reply-To: <20251209131159.4027954-1-dietmar@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1765305068129 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.022 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: Re: [yew-devel] [RFC yew-comp] refactor: move LoadableComponent state into component implementations X-BeenThere: yew-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Yew framework devel list at Proxmox List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Yew framework devel list at Proxmox Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: yew-devel-bounces@lists.proxmox.com Sender: "yew-devel" Am 09.12.25 um 15:36 schrieb Dietmar Maurer: > Major Refactoring of the `LoadableComponent` system. > > Encapsulate component state (loading, error, view_state) into a new > `LoadableComponentState` struct. > Instead of `LoadableComponentMaster` managing the state externally, > the concrete components now own their `LoadableComponentState`. > > - Use `impl_deref_mut_property`LoadableComponentState` struct. to implement > Deref/DerefMut for components, allowing `LoadableComponentMaster` to > access the state transparently. > - `LoadableComponentContext` is now a normal yew Scope (removed custom implementation) > - Migrate all `LoadableComponent` implementations (ACL, ACME, APT, Network, > User/Token/TFA views, etc.) to the new pattern. > - Use `link.custom_callback` and `link.send_custom_message` for internal > messaging (rename is necessaray because of naming conflict with standard s/necessaray/necessary/ > Scope function). > - avoid useless Redraw/Datachange/Refresh messages, because `LoadableComponentMaster` > already implements that. Besides above typo in the commit message and another typo in the doc-comment example (see below), this looks OK to me. > diff --git a/src/loadable_component.rs b/src/loadable_component.rs > index f0e28a9..43cb7a9 100644 > --- a/src/loadable_component.rs > +++ b/src/loadable_component.rs > @@ -1,163 +1,313 @@ > -use anyhow::Error; > -use serde_json::Value; > use std::future::Future; > +use std::ops::DerefMut; > use std::pin::Pin; > -use yew_router::scope_ext::RouterScopeExt; > > +use anyhow::Error; > use gloo_timers::callback::Timeout; > > +use serde_json::Value; > use yew::html::Scope; > > use pwt::dom::DomVisibilityObserver; > use pwt::prelude::*; > -use pwt::state::NavigationContextExt; > use pwt::widget::{AlertDialog, Column}; > use pwt::AsyncPool; > > +#[cfg(doc)] > +use crate::impl_deref_mut_property; > +#[cfg(doc)] > +use pwt::widget::Dialog; > + > use crate::{TaskProgress, TaskViewer}; > > -pub struct LoadableComponentState { > - loading: usize, > - last_load_error: Option, > - repeat_timespan: u32, /* 0 => no repeated loading */ > - task_base_url: Option, > -} > +pub type LoadableComponentContext = Context>; > +pub type LoadableComponentScope = Scope>; > + > +/// Loadable Components > +/// > +/// - Load data using an async function [LoadableComponent::load] > +/// - repeated load possible > +/// - pause repeated load when component is not visible (uses [DomVisibilityObserver]) > +/// - display the loaded data [LoadableComponent::main_view] > +/// - display an optional toolbar [LoadableComponent::toolbar] > +/// - display any errors from failed load. > +/// - display additional dialogs depening on [LoadableComponent::ViewState] > +/// > +/// The [LoadableComponentScopeExt] defines available control function on the scope. > +/// > +/// The [LoadableComponentState] provides acces to load status informations and add the ability > +/// to spawn tasks. > +/// > +/// ``` > +/// use proxmox_yew_comp::{LoadableComponent, LoadableComponentState, LoadableComponentContext}; > +/// // include the scope extension for (for `change_view`, `send_custom_message`, ...) > +/// use proxmox_yew_comp::LoadableComponentScopeExt; > +/// # use std::pin::Pin; > +/// # use std::rc::Rc; > +/// # use std::future::Future; > +/// # use pwt::prelude::*; > +/// # use proxmox_yew_comp::http_get; > +/// # use yew::virtual_dom::{VComp, VNode, Key}; > +/// > +/// // define the component properties > +/// #[derive(Clone, PartialEq, Properties)] > +/// pub struct MyComponent { > +/// key: Option, > +/// /* add whatever you need */ > +/// }; > +/// > +/// // define your view states > +/// #[derive(PartialEq)] > +/// pub enum ViewState { Add, Edit } > +/// > +/// // define the component message type > +/// pub enum Msg { UpdateData(String) } > +/// > +/// // define the component state > +/// pub struct MyComponentState { > +/// // you need to inlucde a LoadableComponentState typo s/inlucde/include/ > +/// state: LoadableComponentState, > +/// // Add any other data you need > +/// loaded_data: Option, > +/// } > +/// > +/// // implement DerefMut > +/// proxmox_yew_comp::impl_deref_mut_property!( > +/// MyComponentState, > +/// state, > +/// LoadableComponentState > +/// ); > +/// _______________________________________________ yew-devel mailing list yew-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel