FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

refactor: simplify ComponentRegistry sub-component API · patternfly-java/patternfly-java@af2992d · GitHub

Commit af2992d

Browse files
committed
refactor: simplify ComponentRegistry sub-component API
Pass SubComponent directly to registerSubComponent() instead of separate type/name parameters. Remove unused unregister methods.
1 parent b406346 commit af2992d

2 files changed

Lines changed: 11 additions & 19 deletions

File tree

‎components/src/main/java/org/patternfly/component/ComponentRegistry.java‎

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323
import elemental2.dom.HTMLElement;
2424

2525
/**
26-
* Public, type-keyed singleton registry for PatternFly components that exist at most once per page. Use this class
27-
* to register and look up global components such as {@link org.patternfly.component.page.Page},
26+
* Public, type-keyed singleton registry for PatternFly components that exist at most once per page. Use this class to register
27+
* and look up global components such as {@link org.patternfly.component.page.Page},
2828
* {@link org.patternfly.component.page.Masthead}, or {@link org.patternfly.component.notification.NotificationDrawerList}.
2929
* <p>
3030
* This is distinct from {@link ComponentStore}, which is an internal, package-private store for wiring parent-child
3131
* relationships via DOM traversal and supports multiple instances of the same {@link ComponentType}.
3232
* <p>
3333
* Registration is done by calling {@link #registerComponent(ComponentType, BaseComponent)} or
3434
* {@link #registerSubComponent(ComponentType, String, SubComponent)}. Lookup is done by calling
35-
* {@link #lookupComponent(ComponentType)} and {@link #lookupSubComponent(ComponentType, String)}.
36-
* When a registered component is removed from the DOM, call {@link #unregisterComponent(ComponentType)} or
35+
* {@link #lookupComponent(ComponentType)} and {@link #lookupSubComponent(ComponentType, String)}. When a registered component
36+
* is removed from the DOM, call {@link #unregisterComponent(ComponentType)} or
3737
* {@link #unregisterSubComponent(ComponentType, String)} to prevent stale references.
3838
*/
3939
public class ComponentRegistry {
@@ -65,16 +65,8 @@ public void registerComponent(ComponentType type, BaseComponent<?, ?> component)
6565
components.put(type, component);
6666
}
6767

68-
public void registerSubComponent(ComponentType type, String name, SubComponent<?, ?> subComponent) {
69-
subComponents.put(subComponentKey(type, name), subComponent);
70-
}
71-
72-
public void unregisterComponent(ComponentType type) {
73-
components.remove(type);
74-
}
75-
76-
public void unregisterSubComponent(ComponentType type, String name) {
77-
subComponents.remove(subComponentKey(type, name));
68+
public void registerSubComponent(SubComponent<?, ?> subComponent) {
69+
subComponents.put(subComponentKey(subComponent.componentType, subComponent.subComponentId), subComponent);
7870
}
7971

8072
@SuppressWarnings("unchecked")
@@ -85,13 +77,13 @@ public <C extends BaseComponent<E, B>, E extends HTMLElement, B extends TypedBui
8577

8678
@SuppressWarnings("unchecked")
8779
public <C extends SubComponent<E, B>, E extends HTMLElement, B extends TypedBuilder<E, B>> C lookupSubComponent(
88-
ComponentType type, String name) {
89-
return (C) subComponents.get(subComponentKey(type, name));
80+
ComponentType type, String id) {
81+
return (C) subComponents.get(subComponentKey(type, id));
9082
}
9183

9284
// ------------------------------------------------------ internal
9385

94-
private String subComponentKey(ComponentType componentType, String name) {
95-
return componentType.id + name;
86+
private String subComponentKey(ComponentType componentType, String id) {
87+
return componentType.id + id;
9688
}
9789
}

‎components/src/main/java/org/patternfly/component/SubComponent.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public E element() {
7878
}
7979

8080
public B registerSubComponent() {
81-
componentRegistry().registerSubComponent(componentType, subComponentId, this);
81+
componentRegistry().registerSubComponent(this);
8282
return that();
8383
}
8484

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL