From 184b0e70d247237472c97b5f4c7fdd9a03251914 Mon Sep 17 00:00:00 2001 From: Nicolas Cannasse Date: Thu, 23 Jan 2025 08:08:41 +0100 Subject: [PATCH] fixed load css of not compiled components --- hrt/impl/DomkitViewer.hx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/hrt/impl/DomkitViewer.hx b/hrt/impl/DomkitViewer.hx index a50fbba7..802dfb7c 100644 --- a/hrt/impl/DomkitViewer.hx +++ b/hrt/impl/DomkitViewer.hx @@ -205,18 +205,24 @@ class DomkitViewer extends h2d.Object { var loadedComponents : Array> = []; var compHooks : Map -> h2d.Object -> h2d.Object> = []; var definedClasses : Array = []; - var loadedResources : Array; + var loadedResources : Array<{ r : hxd.res.Resource, wasLoaded : Bool }> = []; public function new( style : DomkitStyle, res : hxd.res.Resource, ?parent ) { super(parent); this.style = style; this.resource = res; - loadedResources = [res]; - res.watch(rebuild); + loadComponents(res); addContext(new DomkitBaseContext()); rebuildDelay(); } + function loadComponents( res : hxd.res.Resource ) { + var loaded = @:privateAccess style.resources.indexOf(res) >= 0; + loadedResources.push({ r : res, wasLoaded: loaded }); + if( !loaded ) style.load(res); + res.watch(rebuild); + } + function rebuildDelay() { if( rebuilding ) return; rebuilding = true; @@ -264,8 +270,12 @@ class DomkitViewer extends h2d.Object { if( currentObj != null ) currentObj.remove(); // force re-watch - for( r in loadedResources ) - style.load(r); + for( r in loadedResources ) { + if( r.wasLoaded ) + style.load(r.r); + else + style.unload(r.r); + } for( c in loadedComponents ) { @:privateAccess domkit.Component.COMPONENTS.remove(c.name); @:privateAccess domkit.CssStyle.CssData.COMPONENTS.remove(c);