@mica/sdk (SDK contract v1)
    Preparing search index...

    Function lazyBadge

    • A launcher badge count, composed the first time something reads it.

      badgeStore is read when an app is registered, which is the earliest moment in the phone's life — earlier than any component, and earlier than the SDK barrel has finished evaluating. So a manifest that calls a hook at module scope to build its count crashes with useX is not a function: shell/state/registry.ts globs every manifest, and a manifest importing @mica/sdk closes a cycle back onto a module that is still initializing.

      This defers the composition to the first subscribe, by which point every module is up. The launcher subscribes when it paints, which is exactly when the number first matters.

      badgeStore: lazyBadge(() => {
      const { unreadCount } = useNotifications('my_app');
      return unreadCount;
      })

      The alternative was for the SDK to export each app's finished badge store — which is how this started, with a blabberTotalUnread sitting in sdk/utils.ts. That made the contract every app builds against hold a hardcoded reference to one app's service, so an add-on the SDK has never heard of could not produce a badge at all. What a badge counts is the app's business; when it may be computed is the platform's.

      Parameters

      • compose: () => Readable<number> | Promise<Readable<number>>

      Returns Readable<number>