Version: 3.99.0.26
calm-evt: event wrapper that calms an event’s delivery.
(require (planet "calm-evt.ss" ("dyoo" "calm-evt.plt" 1 0))) |
calm-evt wraps around events and calms them down. It’s meant
to be similar to the behavior of
calm-e in the
Flapjax language.
1 Example
Examples: |
> (module exercise-calm-evt mzscheme | (require (lib "mred.ss" "mred") | (lib "class.ss") | (lib "async-channel.ss") | (planet "calm-evt.ss" ("dyoo" "calm-evt.plt" 1))) | | (provide test) | | (define text%/changed-notification | (class text% | (inherit get-text) | (define notify-channel (make-async-channel)) | | (define/public (get-notify-channel) | notify-channel) | | (define/augment (after-insert pos len) | (inner (void) after-insert pos len) | (async-channel-put notify-channel (get-text))) | | (define/augment (after-delete pos len) | (inner (void) after-delete pos len) | (async-channel-put notify-channel (get-text))) | | (super-new))) | | | (define (test) | (parameterize ([current-eventspace (make-eventspace)]) | (define f (new frame% [label ""])) | (define t (new text%/changed-notification)) | (define c (new editor-canvas% | [parent f] | [editor t])) | (send f show #t) | | (thread | (lambda () | (define delayed-change-evt | (make-calm-evt (send t get-notify-channel))) | (let loop () | (sync (handle-evt delayed-change-evt | (lambda (val) | (printf "~s~n" val)))) | (loop)))) | (void)))) |
|
Run the test function, and then start typing in the new
frame. Changes in the text will be printed out, but only after a
period of inactivity.
2 API
A calm-evt can be used as an argument to sync. Its
result is the result of the event that it wraps.
(make-calm-evt | | wrapped-evt | | | | | | [ | delay-in-milliseconds]) | | → | | calm-evt? |
|
wrapped-evt : evt? |
delay-in-milliseconds : natural-number/c = 1000 |
Creates a new calm-evt that wraps around the wrapped-evt.
(calm-evt? datum) → boolean? |
datum : any/c |
Returns true if the datum is a calm-evt.