Skip to content

Commit 8220482

Browse files
Pass ComponentDefinition as parameter to ComponentReference construction
1 parent 64de674 commit 8220482

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

ng-appserver/src/main/java/ng/appserver/NGComponentDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public NGComponent componentInstanceInContext( final NGContext context ) {
172172
* @return A new component reference to insert into a template being rendered
173173
*/
174174
public NGComponentReference componentReferenceWithAssociations( final Map<String, NGAssociation> associations, final NGElement contentTemplate ) {
175-
return new NGComponentReference( name(), associations, contentTemplate );
175+
return NGComponentReference.of( this, associations, contentTemplate );
176176
}
177177

178178
/**

ng-appserver/src/main/java/ng/appserver/NGComponentReference.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package ng.appserver;
22

33
import java.util.Map;
4-
import java.util.Objects;
54

65
import ng.appserver.elements.NGStructuralElement;
76

@@ -14,7 +13,7 @@ public class NGComponentReference extends NGDynamicElement implements NGStructur
1413
/**
1514
* Holds a reference to the fully qualified class name of the component we're going to render
1615
*/
17-
private final NGComponentDefinition _componentDefinition;
16+
private NGComponentDefinition _componentDefinition;
1817

1918
/**
2019
* The bindings being passed from the parent component to the component being rendered.
@@ -35,13 +34,21 @@ public class NGComponentReference extends NGDynamicElement implements NGStructur
3534
*/
3635
public NGComponentReference( final String componentName, final Map<String, NGAssociation> associations, final NGElement contentTemplate ) {
3736
super( null, null, null );
38-
Objects.requireNonNull( componentName );
39-
Objects.requireNonNull( associations );
40-
_componentDefinition = NGApplication.application().elementManager().componentDefinition( componentName );
4137
_associations = associations;
4238
_contentTemplate = contentTemplate;
4339
}
4440

41+
/**
42+
* @return A new component reference for the given component definition
43+
*
44+
* CHECKME: A little sucky, but required for passing in the component definition
45+
*/
46+
public static NGComponentReference of( final NGComponentDefinition componentDefinition, final Map<String, NGAssociation> associations, final NGElement contentTemplate ) {
47+
NGComponentReference reference = new NGComponentReference( null, associations, contentTemplate );
48+
reference._componentDefinition = componentDefinition;
49+
return reference;
50+
}
51+
4552
private void beforeComponent( final NGContext context ) {
4653
// Let's take hold of component that's being rendered, before we hand control to the new component
4754
final NGComponent previousComponent = context.component();

ng-appserver/src/main/java/ng/appserver/templating/NGElementManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private static NGComponentDefinition componentDefinition( final Class<? extends
5959
/**
6060
* @return The componentDefinition corresponding to the named NGComponent
6161
*/
62-
public static NGComponentDefinition componentDefinition( final String componentName ) {
62+
private static NGComponentDefinition componentDefinition( final String componentName ) {
6363
Objects.requireNonNull( componentName );
6464
return NGComponentDefinition.get( componentName );
6565
}

0 commit comments

Comments
 (0)