Skip to content

Commit

Permalink
v2.5.9
Browse files Browse the repository at this point in the history
- `UIRootComponent`:
  - Constructor:
    - register at `_rootComponentInstances`, using `WeakReference`.
  - Added `getInstances`.

- `UIComponent`:
  - `_getUIComponentByContent`, `_getUIComponentByChild`:
    - Search first through `UIRoot.getInstance()` and also through `UIRootComponent.getInstances()`.
  • Loading branch information
gmpassos committed Sep 15, 2024
1 parent 0eb8bce commit 6d23c9e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 5 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 2.5.9

- `UIRootComponent`:
- Constructor:
- register at `_rootComponentInstances`, using `WeakReference`.
- Added `getInstances`.

- `UIComponent`:
- `_getUIComponentByContent`, `_getUIComponentByChild`:
- Search first through `UIRoot.getInstance()` and also through `UIRootComponent.getInstances()`.

## 2.5.8

- sdk: '>=3.4.0 <4.0.0'
Expand Down
2 changes: 1 addition & 1 deletion lib/src/bones_ui.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class BonesUI {
static const String version = '2.5.8';
static const String version = '2.5.9';
}
27 changes: 25 additions & 2 deletions lib/src/bones_ui_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1004,12 +1004,35 @@ abstract class UIComponent extends UIEventHandler {

static UIComponent? _getUIComponentByContent(UIElement? content) {
if (content == null) return null;
return UIRoot.getInstance()?.getUIComponentByContent(content);
return _getUIComponent((o) => o.getUIComponentByContent(content));
}

static UIComponent? _getUIComponentByChild(UIElement? content) {
if (content == null) return null;
return UIRoot.getInstance()?.getUIComponentByChild(content);
return _getUIComponent((o) => o.getUIComponentByChild(content));
}

static UIComponent? _getUIComponent(
UIComponent? Function(UIRootComponent uiRootComponent) caller) {
var uiRoot = UIRoot.getInstance();

var uiComponent = uiRoot == null ? null : caller(uiRoot);
if (uiComponent != null) {
return uiComponent;

Check warning on line 1021 in lib/src/bones_ui_component.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_ui_component.dart#L1021

Added line #L1021 was not covered by tests
}

if (uiComponent == null) {
for (var uiRootComponent in UIRootComponent.getInstances()) {
if (uiRootComponent == uiRoot) continue;

uiComponent = caller(uiRootComponent);
if (uiComponent != null) {
return uiComponent;

Check warning on line 1030 in lib/src/bones_ui_component.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_ui_component.dart#L1028-L1030

Added lines #L1028 - L1030 were not covered by tests
}
}
}

return null;
}

UIComponent? findUIComponentByID(String id) {
Expand Down
32 changes: 31 additions & 1 deletion lib/src/bones_ui_root.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,34 @@ import 'component/svg.dart';
/// - Implemented by [UIRoot] and [UIDialogBase].
/// - Handles registration of the tree of [UIComponent]s and sub-[UIComponent]s.
abstract class UIRootComponent extends UIComponent {
static final List<WeakReference<UIRootComponent>> _rootComponentInstances =
[];

/// Returns the current [UIRootComponent] instances.
static List<UIRootComponent> getInstances() {
var instances = <UIRootComponent>[];

List<WeakReference<Object>>? del;

for (var ref in _rootComponentInstances) {
var o = ref.target;
if (o != null) {
instances.add(o);
} else {
del ??= [];
del.add(ref);

Check warning on line 42 in lib/src/bones_ui_root.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_ui_root.dart#L41-L42

Added lines #L41 - L42 were not covered by tests
}
}

if (del != null) {
for (var ref in del) {
_rootComponentInstances.remove(ref);

Check warning on line 48 in lib/src/bones_ui_root.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/bones_ui_root.dart#L47-L48

Added lines #L47 - L48 were not covered by tests
}
}

return instances;
}

UIRootComponent(super.parent,
{super.componentClass,
super.componentStyle,
Expand All @@ -37,7 +65,9 @@ abstract class UIRootComponent extends UIComponent {
super.renderOnConstruction,
super.preserveRender,
super.id,
super.generator});
super.generator}) {
_rootComponentInstances.add(WeakReference(this));
}

late DOMTreeReferenceMap<UIComponent> _uiComponentsTree;

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: bones_ui
description: Bones_UI - An intuitive and user-friendly Web User Interface framework for Dart.
version: 2.5.8
version: 2.5.9
homepage: https://github.com/Colossus-Services/bones_ui

environment:
Expand Down

0 comments on commit 6d23c9e

Please sign in to comment.