@@ -83,7 +83,7 @@ pub mod ssr {
8383pub mod csr {
8484 use frender_common:: { strings:: CsrStr , IntoStaticStrCache , ToAsRefStr } ;
8585
86- use crate :: csr:: CssStyleDeclaration ;
86+ use crate :: csr:: { CsrStyleStateUnmount , CssStyleDeclaration } ;
8787
8888 use super :: DeclarationName ;
8989
@@ -94,42 +94,84 @@ pub mod csr {
9494
9595 pub trait CsrDeclarationName {
9696 type Cacheable : IntoStaticStrCache < StaticStrCache = Self :: StaticCache > ;
97- type StaticCache : ' static ;
97+
98+ /// The [`CsrStyleStateUnmount`] allows to remove this style by name.
99+ type StaticCache : ' static + CsrStyleStateUnmount ;
98100
99101 fn match_cache ( this : & Self , cache : & Self :: StaticCache ) -> bool ;
100102
101103 fn into_cacheable ( this : Self ) -> Self :: Cacheable ;
102104
103105 fn update_style ( this : & Self :: StaticCache , style : impl UpdateStyleWithDeclarationName ) ;
106+ }
107+
108+ pub struct DeclarationNameStrCacheable < S > ( pub S ) ;
109+
110+ pub struct DeclarationNameStrStaticCache < S > ( pub S ) ;
111+
112+ impl < S : IntoStaticStrCache > IntoStaticStrCache for DeclarationNameStrCacheable < S > {
113+ type StaticStrCache = DeclarationNameStrStaticCache < S :: StaticStrCache > ;
114+
115+ fn into_static_str_cache ( self ) -> Self :: StaticStrCache {
116+ DeclarationNameStrStaticCache ( self . 0 . into_static_str_cache ( ) )
117+ }
118+
119+ fn update_into_static_str_cache ( self , cache : & mut Self :: StaticStrCache ) {
120+ self . 0 . update_into_static_str_cache ( & mut cache. 0 )
121+ }
122+ }
123+
124+ impl < S : PartialEq < T > , T > PartialEq < DeclarationNameStrCacheable < T > >
125+ for DeclarationNameStrStaticCache < S >
126+ {
127+ fn eq ( & self , other : & DeclarationNameStrCacheable < T > ) -> bool {
128+ self . 0 == other. 0
129+ }
130+ }
131+
132+ impl < S : ToAsRefStr > ToAsRefStr for DeclarationNameStrStaticCache < S > {
133+ type ToAsRefStr < ' a > = S :: ToAsRefStr < ' a >
134+ where
135+ Self : ' a ;
104136
105- fn remove_style ( this : & Self :: StaticCache , style : & mut impl CssStyleDeclaration ) ;
137+ fn to_as_ref_str ( & self ) -> Self :: ToAsRefStr < ' _ > {
138+ self . 0 . to_as_ref_str ( )
139+ }
140+ }
141+
142+ /// This relies on StrToAsRefStr::to_as_ref_str and StrToStaticCache::IntoToStaticCache would AsRef the same string
143+ impl < S : ToAsRefStr > CsrStyleStateUnmount for DeclarationNameStrStaticCache < S > {
144+ fn csr_style_state_unmount ( this : & mut Self , style : & mut impl CssStyleDeclaration ) {
145+ style. remove_property_str ( this. 0 . to_as_ref_str ( ) . as_ref ( ) )
146+ }
106147 }
107148
108149 impl < S : CsrStr > CsrDeclarationName for S {
109- type Cacheable = S :: IntoIntoStaticStrCache ;
110- type StaticCache = S :: StaticStrCache ;
150+ type Cacheable = DeclarationNameStrCacheable < S :: IntoIntoStaticStrCache > ;
151+ type StaticCache = DeclarationNameStrStaticCache < S :: StaticStrCache > ;
111152
112153 fn match_cache ( this : & Self , cache : & Self :: StaticCache ) -> bool {
113- cache == this
154+ cache. 0 == * this
114155 }
115156
116157 fn into_cacheable ( this : Self ) -> Self :: Cacheable {
117- this. into_into_static_str_cache ( )
158+ DeclarationNameStrCacheable ( this. into_into_static_str_cache ( ) )
118159 }
119160
120161 fn update_style ( this : & Self :: StaticCache , style : impl UpdateStyleWithDeclarationName ) {
121162 style. update_style_with_declaration_name_str ( this. to_as_ref_str ( ) . as_ref ( ) )
122163 }
123-
124- /// This relies on StrToAsRefStr::to_as_ref_str and StrToStaticCache::IntoToStaticCache would AsRef the same string
125- fn remove_style ( this : & Self :: StaticCache , style : & mut impl CssStyleDeclaration ) {
126- style. remove_property_str ( this. to_as_ref_str ( ) . as_ref ( ) )
127- }
128164 }
129165
130166 pub struct CacheableDeclarationName < S > ( S ) ;
131167 pub struct CacheableDeclarationNameIntoStaticStrCache < S > ( S ) ;
132168
169+ impl < S : ToAsRefStr > CsrStyleStateUnmount for CacheableDeclarationNameIntoStaticStrCache < S > {
170+ fn csr_style_state_unmount ( this : & mut Self , style : & mut impl CssStyleDeclaration ) {
171+ style. remove_property ( DeclarationName ( this. 0 . to_as_ref_str ( ) . as_ref ( ) ) )
172+ }
173+ }
174+
133175 impl < S : ToAsRefStr > ToAsRefStr for CacheableDeclarationName < S > {
134176 type ToAsRefStr < ' a > = S :: ToAsRefStr < ' a >
135177 where
@@ -192,9 +234,5 @@ pub mod csr {
192234 this. 0 . to_as_ref_str ( ) . as_ref ( ) ,
193235 ) )
194236 }
195-
196- fn remove_style ( this : & Self :: StaticCache , style : & mut impl CssStyleDeclaration ) {
197- style. remove_property ( DeclarationName ( this. 0 . to_as_ref_str ( ) . as_ref ( ) ) )
198- }
199237 }
200238}
0 commit comments