@@ -33,7 +33,6 @@ public abstract class AbstractComponentView<T extends AbstractComponentViewModel
3333
3434 public AbstractComponentView (T viewModel ) {
3535 this .viewModel = viewModel ;
36- setComposer (createComposer ());
3736 }
3837
3938 @ Override
@@ -95,34 +94,11 @@ public ComponentComposer<?> getComposer() {
9594 return composer ;
9695 }
9796
98- /**
99- * Sets the {@link ComponentComposer} for this view and updates the view model with the corresponding
100- * {@link ComposerMediator}.
101- *
102- * <p>When a non-{@code null} composer is provided, the view becomes associated with that composer, and the view
103- * model receives the mediator obtained via {@link ComponentComposer#getMediator()}. This mediator enables
104- * communication between the view model and the rest of the component through the composer.
105- *
106- * <p>If {@code composer} is {@code null}, the view is detached from any composer, and the view model's mediator
107- * is cleared as well, effectively disconnecting both layers from the component's composition mechanism.
108- *
109- * @param composer the composer to attach to this view, or {@code null} to detach
110- */
111- public void setComposer (ComponentComposer <?> composer ) {
112- this .composer = composer ;
113- if (composer == null ) {
114- viewModel .setMediator (null );
115- } else {
116- viewModel .setMediator (composer .getMediator ());
117- }
118- }
119-
12097 /**
12198 * Creates a new {@link ComponentComposer} instance for this component.
12299 *
123- * <p>This method is invoked during the component's construction phase and allows subclasses to provide a custom
124- * composer implementation. However, this method should be used only if the component is the owner of the composer.
125- * Otherwise the component setter should be used.
100+ * <p>This method is invoked during the component's pre-initialization phase and allows subclasses to provide
101+ * a custom composer implementation.
126102 *
127103 * <p>The default implementation returns {@code null}, meaning the component does not create a composer by default.
128104 *
@@ -146,7 +122,11 @@ protected ComponentDescriptor getDescriptor() {
146122 * The first method called in initialization.
147123 */
148124 protected void preInitialize (T viewModel ) {
149-
125+ this .composer = createComposer ();
126+ if (this .composer != null ) {
127+ viewModel .setMediator (this .composer .getMediator ());
128+ this .composer .initialize ();
129+ }
150130 }
151131
152132 /**
@@ -230,6 +210,8 @@ protected void unbuild(T viewModel) {
230210 * The last method called in deinitialization.
231211 */
232212 protected void postDeinitialize (T viewModel ) {
233-
213+ if (this .composer != null ) {
214+ this .composer .deinitialize ();
215+ }
234216 }
235217}
0 commit comments