scan method
Scans root (or rootElement, or document) for unhydrated island placeholders.
Creates a BloomIslandInstance for each discovered element and initializes its hydration strategy listener. Returns the list of newly discovered island instances.
final newIslands = orchestrator.scan();
print('Found ${newIslands.length} new islands');
Implementation
List<BloomIslandInstance> scan([web.Element? root]) {
if (_disposed) return const [];
final container = root ?? rootElement ?? web.document.body ?? web.document.documentElement;
if (container == null) return const [];
final selector = '[$bloomIslandAttribute]:not([$bloomHydratedAttribute="true"])';
final nodes = container.querySelectorAll(selector);
final newlyDiscovered = <BloomIslandInstance>[];
for (var i = 0; i < nodes.length; i++) {
final item = nodes.item(i);
if (item == null || !item.isA<web.Element>()) continue;
final el = item as web.Element;
// Skip elements already tracked
if (_islands.any((inst) => inst.element == el)) continue;
final name = el.getAttribute(bloomIslandAttribute);
if (name == null || name.trim().isEmpty) continue;
final def = registry.get(name.trim());
final rawStrategy = el.getAttribute(bloomStrategyAttribute);
final strategy = rawStrategy != null && rawStrategy.isNotEmpty
? HydrationStrategy.parse(rawStrategy, defaultStrategy: def?.defaultStrategy ?? HydrationStrategy.immediate)
: (def?.defaultStrategy ?? HydrationStrategy.immediate);
final props = extractIslandProps(el);
final instance = BloomIslandInstance._(
name: name.trim(),
element: el,
strategy: strategy,
props: props,
orchestrator: this,
);
_islands.add(instance);
newlyDiscovered.add(instance);
_setupStrategyTrigger(instance);
}
return newlyDiscovered;
}