lazy function

BloomNode lazy(
  1. Future<BloomNode> loader(), {
  2. required BloomNode fallback,
})

Creates a lazily loaded BloomNode descriptor that displays fallback until loader resolves.

Under the hood, this wraps loader in a BloomLazyComponent and returns a Suspense node. Calling lazy itself does not initiate loading; loading starts automatically when the node is mounted into the browser DOM or evaluated during streaming SSR (renderToStreamWithSuspense).

In browser applications, combine lazy with Dart's deferred as imports to split heavy feature bundles into separate JavaScript chunks that load on demand.

// Top-level deferred import:
// import 'editor_view.dart' deferred as editor;

BloomNode lazyEditor() => lazy(
  () async {
    // await editor.loadLibrary();
    // return editor.EditorView();
    return const Div(className: 'editor', text: 'Editor Ready');
  },
  fallback: const Div(
    className: 'skeleton-placeholder',
    text: 'Loading editor...',
  ),
);

Implementation

BloomNode lazy(
  Future<BloomNode> Function() loader, {
  required BloomNode fallback,
}) {
  final component = BloomLazyComponent(loader);
  return Suspense<BloomNode>(
    resource: component.load,
    builder: (node) => node,
    fallback: fallback,
  );
}