Skip to content

Commit 4b2edd1

Browse files
committed
Limit update frequency
1 parent cdc9779 commit 4b2edd1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

web/regex_demo.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@
152152
}
153153
$addsamp->click(sub { newsamp('')->click });
154154

155-
our $re_debug=0; #TODO Later: this is actually a parameter to update()
155+
# $re_debug is actually a parameter to update()/actual_update(), but since
156+
# we register &update as a event handler, it'll get passed varying parameters
157+
our $re_debug=0;
156158
my $ta_debugout = $jq->('#debugout');
157159
my $re_debug_hide = $jq->('#re_debug_hide');
158160
$jq->('#re_debug')->click(sub {
@@ -260,6 +262,13 @@
260262
}
261263

262264
sub update {
265+
state $timeout_id;
266+
state $window = js('window');
267+
$window->clearTimeout($timeout_id) if defined $timeout_id;
268+
if ($re_debug) { $timeout_id=undef; actual_update() }
269+
else { $timeout_id = $window->setTimeout(\&actual_update, 100) }
270+
}
271+
sub actual_update {
263272
my $regex = $ta_regex->val;
264273
my $flags = $ta_flags->val;
265274
my $precode = $precode_ta->is(':visible') ? $precode_ta->val : '';

0 commit comments

Comments
 (0)