ui.util.throttle
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
עוטפת פונקציה כדי לאפשר לקרוא לה, לכל היותר, פעמיים בכל מרווח. אם פונקציית העטיפה מופעלת כמה פעמים לפני שההשהיה מסתיימת, רק ההפעלה הראשונה וההפעלה האחרונה יתבצעו.
דוגמה לשימוש: קריאה חוזרת (callback) לאירוע של שקף ב-ui.Slider. הקריאה החוזרת תפעל באופן מיידי, כך שהפעולה של ההחלקה תיראה מהירה. בנוסף, מובטח שהקריאה החוזרת תפעל אחרי שהמשתמש סיים את האינטראקציה עם פס ההזזה, וכך הקריאה החוזרת הסופית תוכל לגשת לערך הסופי של פס ההזזה.
הפונקציה מחזירה את הפונקציה העוטפת.
שימוש | החזרות |
---|
ui.util.throttle(func, delay, scope) | פונקציה |
ארגומנט | סוג | פרטים |
---|
func | פונקציה | הפונקציה שרוצים להפעיל. |
delay | מספר | ההשהיה, באלפיות השנייה, של ההגבלה. אפשר לקרוא לפונקציה רק פעם אחת אחרי הקריאה הראשונית, עד שההשהיה מסתיימת. |
scope | אובייקט, אופציונלי | האובייקט שבהיקף שלו רוצים להפעיל את הפונקציה. |
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-26 (שעון UTC).
[null,null,["עדכון אחרון: 2025-07-26 (שעון UTC)."],[[["\u003cp\u003eLimits a function's execution to at most twice per specified interval, ensuring responsiveness and capturing the final state.\u003c/p\u003e\n"],["\u003cp\u003eUseful for scenarios like UI slider events where immediate feedback and final value processing are crucial.\u003c/p\u003e\n"],["\u003cp\u003eWraps the original function and returns a new function that manages the throttling behavior.\u003c/p\u003e\n"],["\u003cp\u003eCustomizable with a delay parameter (in milliseconds) and an optional scope for execution context.\u003c/p\u003e\n"]]],[],null,["# ui.util.throttle\n\n\u003cbr /\u003e\n\nWraps a function to allow it to be called, at most, twice per interval. If the wrapper function is called multiple times before the delay elapses, only the first and the last calls will go through.\n\n\u003cbr /\u003e\n\nExample use: For the callback to a slide event on a ui.Slider. The callback will run immediately, making the slide action feel responsive. The callback is also guaranteed to run after the user has finished interacting with the slider, ensuring that the final callback invocation has access to the slider's final value.\n\nReturns the wrapped function.\n\n| Usage | Returns |\n|--------------------------------------------|----------|\n| `ui.util.throttle(func, delay, `*scope*`)` | Function |\n\n| Argument | Type | Details |\n|----------|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|\n| `func` | Function | The function to call. |\n| `delay` | Number | The delay, in milliseconds, for the throttle. The function can only be called once after the initial invocation until after the delay has elapsed. |\n| `scope` | Object, optional | The object in whose scope to call the function. |"]]