setOptions method

void setOptions(
  1. QueryOptions<T> value
)

Updates the definition without remounting the same cached query.

A different key or a disabled-to-enabled transition may fetch using the mount policy. Other updates preserve the current request and only affect future fetches, result freshness, and timers.

Implementation

void setOptions(QueryOptions<T> value) {
  if (_disposed) throw StateError('QueryObserver is disposed.');
  final oldQuery = _query;
  final wasEnabled = enabled;
  final nextQuery = client.query(value);
  _options = value;
  _query = nextQuery;
  _resolved = _query.options;
  if (!identical(oldQuery, _query) && _listeners.isNotEmpty) {
    oldQuery.removeObserver(this);
    _query.addObserver(this);
  }
  _updateResult();
  _updateTimers();
  if (_listeners.isNotEmpty &&
      (!identical(oldQuery, _query) || (!wasEnabled && enabled)) &&
      _shouldFetchOnMount()) {
    unawaited(
      _query
          .fetch(options: _resolved, cancelRefetch: false)
          .then<void>((_) {}, onError: (_) {}),
    );
  }
}