Skip to content

remove type variable from base class to actual method #10

@chiptus

Description

@chiptus

the generic type on debounce (and probably also throttle), isn't used anywhere else except the debounce.

if we move the generic type to be only on the debounce method, the same debouncer can be used for different methods.

as in my last issue #9 , I'm trying to wrap the geocode package with a debouncer so it won't call geocode more than 1 once a second. the geocode package has two methods, each of them returns a different type.

it would be nice to be able to do this:

class DebouncedGeoCode {
  final GeoCode geoCode = GeoCode();
  final debouncer =
      Debouncing<Future<Address>>(duration: const Duration(milliseconds: 1000));

  Future<Address?> reverseGeocoding(
      {required double latitude, required double longitude}) async {
    var response = await debouncer.debounce<Future<Address>>(() =>
        geoCode.reverseGeocoding(latitude: latitude, longitude: longitude));
    return await response;
  }

  Future<Coordinates?> forwardGeocoding({required String address}) async {
    var response = await debouncer.debounce(() =>
        geoCode.forwardGeocoding(address: address));
    return await response;
  }
}

using one debouncer is preferable over two because I want to limit every request not just those of the same type

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions