Skip to content

Commit 0c50fde

Browse files
authored
feat: Fragments registration in DuitRegistry (#39)
Added a new static method registerFragment for registering fragments by key and a method getFragment for receiving a fragment by key with logging in case of absence. Also added an internal registry of fragments _fragmentRegistry.
1 parent 4b4c4d1 commit 0c50fde

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

lib/src/registry_api/registry.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:duit_kernel/src/registry_api/components/index.dart';
77
/// model factories, build factories, and attributes factories for custom DUIT elements.
88
sealed class DuitRegistry {
99
static final Map<String, BuildFactory> _customComponentRegistry = {};
10+
static final Map<String, Map<String, dynamic>> _fragmentRegistry = {};
1011
static DebugLogger _logger = DefaultLogger.instance;
1112
static ComponentRegistry _componentRegistry = DefaultComponentRegistry();
1213
static DuitTheme _theme = const DuitTheme({});
@@ -102,4 +103,21 @@ sealed class DuitRegistry {
102103
return null;
103104
}
104105
}
106+
107+
static void registerFragment(
108+
String key,
109+
Map<String, dynamic> fragment,
110+
) {
111+
_fragmentRegistry[key] = fragment;
112+
}
113+
114+
static Map<String, dynamic>? getFragment(String key) {
115+
final fragment = _fragmentRegistry[key];
116+
if (fragment != null) {
117+
return fragment;
118+
} else {
119+
_logger.warn("Not found fragment for specified key - $key");
120+
return null;
121+
}
122+
}
105123
}

0 commit comments

Comments
 (0)