createManager method

  1. @override
DatumManager<T> createManager(
  1. Datum datum
)
override

Implementation

@override
DatumManager<T> createManager(Datum datum) {
  // This is a testing hook. If the config is a special type, return the mock manager from it.
  // This allows us to inject a mock manager during Datum.initialize() in tests.
  final registrationConfig = config ?? datum.config.copyWith<T>();
  if (registrationConfig is CustomManagerConfig<T>) {
    final customConfig = registrationConfig;
    // Return the mock manager provided by the custom config.
    // We still need to pass some dependencies to it for initialization.
    // This part is a bit of a hack for testing purposes.
    return customConfig.mockManager;
  }

  // Keep specific return type here
  final manager = DatumManager<T>(
    localAdapter: local,
    remoteAdapter: remote,
    conflictResolver: conflictResolver,
    localObservers: observers,
    globalObservers: datum.globalObservers,
    middlewares: middlewares,
    datumConfig: registrationConfig,
    connectivity: datum.connectivityChecker,
    logger: datum.logger,
    syncRequestStrategy: syncRequestStrategy,
  );
  return manager;
}