[beast/ebeast] EBEAST: widgets.js: provide helpers for AnimationFrame callbacks
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast/ebeast] EBEAST: widgets.js: provide helpers for AnimationFrame callbacks
- Date: Tue, 7 Mar 2017 22:48:07 +0000 (UTC)
commit bf05c70e7e3973c37644096266d6392221e3b5fd
Author: Tim Janik <timj gnu org>
Date: Tue Mar 7 00:42:53 2017 +0100
EBEAST: widgets.js: provide helpers for AnimationFrame callbacks
Signed-off-by: Tim Janik <timj gnu org>
ebeast/assets/widgets.js | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/ebeast/assets/widgets.js b/ebeast/assets/widgets.js
index fe94e1a..249a35d 100644
--- a/ebeast/assets/widgets.js
+++ b/ebeast/assets/widgets.js
@@ -10,3 +10,25 @@ module.exports.KeyCode = {
VOLUMEMUTE: 173, VOLUMEDOWN: 174, VOLUMEUP: 175, MEDIANEXTTRACK: 176, MEDIAPREVIOUSTRACK: 177, MEDIASTOP:
178, MEDIAPLAYPAUSE: 179,
};
+// == Utility Functions ==
+
+/// Wrap @a callback so it's only called once per AnimationFrame.
+function create_animation_callback (callback) {
+ return function() {
+ if (true === !callback.__create_animation_callback__pending__) {
+ const request_id = requestAnimationFrame (function (now_ms) {
+ callback.__create_animation_callback__pending__ = undefined;
+ callback (now_ms);
+ });
+ callback.__create_animation_callback__pending__ = request_id;
+ }
+ };
+}
+module.exports.create_animation_callback = create_animation_callback;
+
+/// Enqueue @a callback to be executed once at the next AnimationFrame.
+function queue_animation_callback (callback) {
+ const queue_callback = create_animation_callback (callback);
+ queue_callback();
+}
+module.exports.queue_animation_callback = queue_animation_callback;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]