| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,17 +23,17 @@ | |||
| 23 | 23 | import elemental2.dom.HTMLElement; | |
| 24 | 24 | ||
| 25 | 25 | /** | |
| 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}, | ||
| 28 | 28 | * {@link org.patternfly.component.page.Masthead}, or {@link org.patternfly.component.notification.NotificationDrawerList}. | |
| 29 | 29 | * <p> | |
| 30 | 30 | * This is distinct from {@link ComponentStore}, which is an internal, package-private store for wiring parent-child | |
| 31 | 31 | * relationships via DOM traversal and supports multiple instances of the same {@link ComponentType}. | |
| 32 | 32 | * <p> | |
| 33 | 33 | * Registration is done by calling {@link #registerComponent(ComponentType, BaseComponent)} or | |
| 34 | 34 | * {@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 | ||
| 37 | 37 | * {@link #unregisterSubComponent(ComponentType, String)} to prevent stale references. | |
| 38 | 38 | */ | |
| 39 | 39 | public class ComponentRegistry { | |
@@ -65,16 +65,8 @@ public void registerComponent(ComponentType type, BaseComponent<?, ?> component) | |||
| 65 | 65 | components.put(type, component); | |
| 66 | 66 | } | |
| 67 | 67 | ||
| 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); | ||
| 78 | 70 | } | |
| 79 | 71 | ||
| 80 | 72 | @SuppressWarnings("unchecked") | |
@@ -85,13 +77,13 @@ public <C extends BaseComponent<E, B>, E extends HTMLElement, B extends TypedBui | |||
| 85 | 77 | ||
| 86 | 78 | @SuppressWarnings("unchecked") | |
| 87 | 79 | 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)); | ||
| 90 | 82 | } | |
| 91 | 83 | ||
| 92 | 84 | // ------------------------------------------------------ internal | |
| 93 | 85 | ||
| 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; | ||
| 96 | 88 | } | |
| 97 | 89 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -78,7 +78,7 @@ public E element() { | |||
| 78 | 78 | } | |
| 79 | 79 | ||
| 80 | 80 | public B registerSubComponent() { | |
| 81 | - componentRegistry().registerSubComponent(componentType, subComponentId, this); | ||
| 81 | + componentRegistry().registerSubComponent(this); | ||
| 82 | 82 | return that(); | |
| 83 | 83 | } | |
| 84 | 84 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments