use<T extends OrbitStore> static method

T use<T extends OrbitStore>(
  1. T create()
)

Returns the singleton instance of store T, creating it via create the first time it's requested. Every later call — from any widget, anywhere — returns that same instance.

Implementation

static T use<T extends OrbitStore>(T Function() create) {
  _registerServiceExtension();
  final existing = _stores[T];
  if (existing != null) return existing as T;
  final store = create();
  _stores[T] = store;
  try {
    store._runInit();
  } catch (_) {
    // A synchronous throw from init() — don't leave a broken store
    // in the registry; the next use<T>() call gets a clean retry.
    _stores.remove(T);
    store.dispose();
    rethrow;
  }
  return store;
}