2828import org .apache .commons .collections4 .multimap .ArrayListValuedHashMap ;
2929import org .apache .commons .collections4 .multimap .HashSetValuedHashMap ;
3030import org .apache .commons .lang3 .ClassUtils ;
31+ import org .jetbrains .annotations .MustBeInvokedByOverriders ;
3132import org .jetbrains .annotations .NotNull ;
3233
3334import java .util .*;
@@ -74,6 +75,14 @@ public <T extends R> T addComponent(@NotNull ComponentToken<T> token)
7475 this .components .put (token , component );
7576 this .tokens .put (component , token );
7677
78+ this .onComponentAdded (component );
79+
80+ return component ;
81+ }
82+
83+ @ MustBeInvokedByOverriders
84+ protected void onComponentAdded (R component )
85+ {
7786 try
7887 {
7988 component .initialize (this );
@@ -82,8 +91,6 @@ public <T extends R> T addComponent(@NotNull ComponentToken<T> token)
8291 {
8392 throw new RuntimeException ("An exception has occured while mounting the component" , e );
8493 }
85-
86- return component ;
8794 }
8895
8996 public Class <R > getComponentBase ()
@@ -130,6 +137,12 @@ public void removeComponent(@NotNull R component) throws IllegalArgumentExceptio
130137
131138 classes .forEach (clazz -> this .implementationProviders .removeMapping (clazz , component ));
132139
140+ this .onComponentRemoved (component );
141+ }
142+
143+ @ MustBeInvokedByOverriders
144+ protected void onComponentRemoved (R component )
145+ {
133146 try
134147 {
135148 component .destroy (this );
@@ -151,14 +164,7 @@ public <T extends R> void removeComponents(@NotNull ComponentToken<T> componentT
151164
152165 classes .forEach (clazz -> this .implementationProviders .removeMapping (clazz , component ));
153166
154- try
155- {
156- component .onUnmount ();
157- }
158- catch (Exception e )
159- {
160- throw new RuntimeException ("An exception has occured whiile unmounting the component" , e );
161- }
167+ this .onComponentRemoved (component );
162168 });
163169 }
164170}
0 commit comments