Bladeren bron

refactor: introduce Renderable interface for component abstraction

Add Renderable interface that Component now implements, enabling
decoupling of rendering behavior from the Component hierarchy. The
interface defines get_status() and populate() methods with default
implementations in Component.

The to_result() method is simplified to use get_status() internally
rather than accepting a status parameter.
Billy Barrow 1 week geleden
bovenliggende
commit
860a561371
3 gewijzigde bestanden met toevoegingen van 21 en 4 verwijderingen
  1. 10 4
      src/Component.vala
  2. 10 0
      src/Renderable.vala
  3. 1 0
      src/meson.build

+ 10 - 4
src/Component.vala

@@ -5,14 +5,20 @@ using Astralis;
 
 namespace Spry {
 
-    public abstract class Component : Object {
+    public abstract class Component : Object, Renderable {
         
         private static Dictionary<Type, ComponentTemplate> templates;
         private static Mutex templates_lock = Mutex();
         
         public abstract string markup { get; }
+        public virtual StatusCode get_status() {
+            return StatusCode.OK;
+        }
+        public virtual async void populate(Properties properties) throws Error {
+            // No-op default
+        }
         
-        private Catalogue<string, Component> _children = new Catalogue<string, Component>();
+        private Catalogue<string, Renderable> _children = new Catalogue<string, Renderable>();
         private MarkupDocument _instance;
 
         private MarkupDocument instance { get {
@@ -117,8 +123,8 @@ namespace Spry {
             return final_instance;
         }
 
-        public HttpResult to_result(StatusCode status = StatusCode.OK) throws Error {
-            return to_document().to_result(status);
+        public HttpResult to_result() throws Error {
+            return to_document().to_result(get_status());
         }
 
         private class ComponentTemplate : MarkupTemplate {

+ 10 - 0
src/Renderable.vala

@@ -0,0 +1,10 @@
+using Astralis;
+namespace Spry {
+
+    public interface Renderable : Object {
+
+        public abstract MarkupDocument to_document() throws Error;
+
+    }
+
+}

+ 1 - 0
src/meson.build

@@ -1,5 +1,6 @@
 sources = files(
     'Component.vala',
+    'Renderable.vala',
     'ComponentEndpoint.vala',
     'Context.vala',
     'StyleProvider.vala',