throttle_debounce 0.1.2+1

  • README.md
  • Example
  • Installing
  • Versions
  • 7

Dart throttle/debounce #

A library for throttling or debouncing frequently occuring events. This package is inspired by jquery throttle/debounce http://benalman.com/projects/jquery-throttle-debounce-plugin

Example #

import 'package:throttle_debounce/throttle_debounce.dart';
import 'dart:html' as html;
main() {
    html.Element input = html.querySelector('#inputBox');
    List args = ['argument1', 'argument2'];
    var debouncer = new Debouncer(const Duration(milliseconds:250), callback, args);
    input.onKeyUp.listen((e) {
        debouncer.debounce();
    });
}

void callback(List args) {
    print(args[0]); //will print 'argument1'
    print(args[1]); //will print 'argument2'
}

Throttle #

Execute a frequently called function only once in a fixed interval. See http://benalman.com/code/projects/jquery-throttle-debounce/examples/throttle/ for example of throttling.

Usage and Arguments #

var throttler = new Throttler(Duration delay, callback, List args, [bool noTrailing]);
element.onKeyUp.listen((e) {
    throttler.throttle();
});

delay - (const Duration) A dart constant of type Duration which.

callback - (Function) A function which is executed after delay milliseconds.

args - (List) argument passed to the callback. (Dart does not support variable number of arguments to a function, so we have to pass the arguments in a list)

noTrailing - (bool) Optional, defaults to false. If noTrailing is true, callback will be called after delay only when the throttle function is being called. If set to false, there will also be one trailing call to the callback after delay after the throttle function has stopped executing.

Debouncing #

Debounces the execution of a function. This ensures that the function is executed only once, either at the beginning of a series of calls or at the end. See http://benalman.com/code/projects/jquery-throttle-debounce/examples/debounce/ for example of debouncing.

Usage and Arguments #

var debouncer = new Debouncer(Duration delay, callback, List args, [bool atBegin]);
element.onKeyUp.listen((e) {
    debouncer.debounce();
});

delay - (const Duration) A dart constant of type Duration which.

callback - (Function) A function which is executed after delay milliseconds.

args - (List) argument passed to the callback. (Dart does not support variable number of arguments to a function, so we have to pass the arguments in a list)

atBegin - (bool) Optional, defaults to false. If atBegins is true, the callback will be executed at the beginning of the debounced call. If there is a pause of delay duration, callback will again be called when the debounced call starts again. If atBegins is false, callback will be executed whenever there is a pause of delay duration between the debounce calls i.e. at the end.

Licenses #

Licensed under MIT

Acknowledgement #

Inspired by Jquery throttle/debounce plugin of Ben Alman (http://benalman.com)

example/main.dart

import 'package:throttle_debounce/throttle_debounce.dart';
import 'dart:html' as html;


main() {
  html.Element input1 = html.querySelector('#inputBox1');
  var debouncer = new Debouncer(const Duration(milliseconds:250), callback, ['called'], true); 
  input1.onKeyUp.listen((e) {
    debouncer.debounce();
  });
  html.Element input2 = html.querySelector('#inputBox2');
  var throttler = new Throttler(const Duration(milliseconds:250), callback, ['throttled'], true);
  input2.onKeyUp.listen((e) {
    throttler.throttle();
  });
}

callback(List args) {
  print(args[0]);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  throttle_debounce: ^0.1.2+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:throttle_debounce/throttle_debounce.dart';
  
Version Uploaded Documentation Archive
0.1.2+1 Nov 6, 2016 Go to the documentation of throttle_debounce 0.1.2+1 Download throttle_debounce 0.1.2+1 archive
0.1.2 Sep 15, 2014 Go to the documentation of throttle_debounce 0.1.2 Download throttle_debounce 0.1.2 archive
0.1.1 Sep 14, 2014 Go to the documentation of throttle_debounce 0.1.1 Download throttle_debounce 0.1.1 archive
0.1.0 Sep 14, 2014 Go to the documentation of throttle_debounce 0.1.0 Download throttle_debounce 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
13
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
7
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.