Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / docs / api / Ext.util.DelayedTask.html
1 <!DOCTYPE html><html><head><title>Ext.util.DelayedTask | Ext JS 4.0 Documentation</title><script type="text/javascript" src="../ext-all.js"></script><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../scrollbars.css" type="text/css"><link rel="stylesheet" href="../docs.css" type="text/css"><link id="styleCss" rel="stylesheet" href="../style.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script><link rel="stylesheet" href="../prettify.css" type="text/css"><!-- link(rel: 'stylesheet', href: req.baseURL + '/css/ext4.css', type: 'text/css')--><link rel="shortcut icon" type="image/ico" href="../favicon.ico"><!--[if IE]>
2 <style type="text/css">.head-band { display: none; }
3 .header { border: 0; top: 0; left: 0px; background: url(../header.gif) repeat-x; }
4 .doc-tab .members .member a.more { background-color: #efefef; }
5 </style><link rel="stylesheet" href="/new/css/ie.css" type="text/css"><![endif]-->
6 </head><body id="ext-body" class="iScroll"><div id="notice" class="notice">For up to date documentation and features, visit 
7 <a href="http://docs.sencha.com/ext-js/4-0">http://docs.sencha.com/ext-js/4-0</a></div><div class="wrapper"><div class="head-band"></div><div class="header"><h2><a href="../index.html">Sencha Documentation</a></h2></div><div id="search"><form><input type="text" placeholder="Search" id="search-field" autocomplete="off" name="q"></form><div id="search-box"></div></div><div id="treePanel"></div><div id="container"><script type="text/javascript">
8
9     req = {
10         liveURL: '.',
11         standAloneMode: true,
12         origDocClass: 'Ext.util.DelayedTask',
13         docClass: 'Ext.util.DelayedTask',
14         docReq: 'Ext.util.DelayedTask',
15         version: '4.0',
16         baseURL: '.',
17         baseDocURL: '.',
18         baseProdURL: '.'
19     };
20
21     clsInfo = {};
22
23
24
25 </script>
26
27 <script type="text/javascript" src="../search.js"></script>
28 <!--script type="text/javascript" src="/new/javascripts/app/examples.js"></script-->
29 <script type="text/javascript" src="../class_tree.js"></script>
30 <script type="text/javascript" src="../class_doc.js"></script>
31 <script type="text/javascript">
32     req.source = 'DelayedTask.html#Ext-util.DelayedTask';
33     clsInfo = {"methods":["DelayedTask","cancel","delay"],"cfgs":[],"properties":[],"events":[],"subclasses":[]};
34     Ext.onReady(function() {
35         Ext.create('Docs.classPanel');
36     });
37 </script><div id="top-block" class="top-block"><h1 id="clsTitle" class="cls"><a href="../source/DelayedTask.html#Ext-util.DelayedTask" target="_blank">Ext.util.DelayedTask</a></h1></div><div id="docContent"><div id="doc-overview-content"><div class="lft"><p>The DelayedTask class provides a convenient way to "buffer" the execution of a method,
38 performing setTimeout where a new timeout cancels the old timeout. When called, the
39 task will wait the specified time period before executing. If durng that time period,
40 the task is called again, the original call will be cancelled. This continues so that
41 the function is only called a single time for each iteration.</p>
42
43 <p>This method is especially useful for things like detecting whether a user has finished
44 typing in a text field. An example would be performing validation on a keypress. You can
45 use this class to buffer the keypress events for a certain number of milliseconds, and
46 perform only if they stop for that amount of time.</p>
47
48 <h2>Usage</h2>
49
50 <pre class="prettyprint"><code>var task = new Ext.util.DelayedTask(function(){
51     alert(Ext.getDom('myInputField').value.length);
52 });
53
54 // Wait 500ms before calling our function. If the user presses another key
55 // during that 500ms, it will be cancelled and we'll wait another 500ms.
56 Ext.get('myInputField').on('keypress', function(){
57     task.<a href="Ext.util.DelayedTask.html#delay" rel="Ext.util.DelayedTask#delay" class="docClass">delay</a>(500);
58 });
59 </code></pre>
60
61 <p>Note that we are using a DelayedTask here to illustrate a point. The configuration
62 option <code>buffer</code> for <a href="Ext.util.Observable.html#addListener" rel="Ext.util.Observable#addListener" class="docClass">addListener/on</a> will
63 also setup a delayed task for you to buffer events.</p>
64 <div class="members"><div class="m-methods"><a name="methods"></a><div class="definedBy">Defined By</div><h3 class="mth p">Methods</h3><div id="method-DelayedTask" class="member f ni"><a href="Ext.util.DelayedTask.html#method-DelayedTask" rel="method-DelayedTask" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.DelayedTask.html" class="definedIn docClass">Ext.util.DelayedTask</a><br/><a href="../source/DelayedTask.html#Ext-util.DelayedTask-method-constructor" class="viewSource">view source</a></div><a name="DelayedTask"></a><a name="method-DelayedTask"></a><a href="Ext.util.DelayedTask.html#" rel="method-DelayedTask" class="cls expand">DelayedTask</a>(
65 <span class="pre">[Function fn], Object scope, [Array args]</span>)
66  : void</div><div class="description"><div class="short"><p>The parameters to this constructor serve as defaults and are not required.</p>
67 </div><div class="long"><p>The parameters to this constructor serve as defaults and are not required.</p>
68 <h3 class="pa">Parameters</h3><ul><li><span class="pre">fn</span> : Function<div class="sub-desc"><p>(optional) The default function to call.</p>
69 </div></li><li><span class="pre">scope</span> : Object<div class="sub-desc"><p>The default scope (The <code><b>this</b></code> reference) in which the
70 function is called. If not specified, <code>this</code> will refer to the browser window.</p>
71 </div></li><li><span class="pre">args</span> : Array<div class="sub-desc"><p>(optional) The default Array of arguments.</p>
72 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
73 </li></ul></div></div></div><div id="method-cancel" class="member ni"><a href="Ext.util.DelayedTask.html#method-cancel" rel="method-cancel" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.DelayedTask.html" class="definedIn docClass">Ext.util.DelayedTask</a><br/><a href="../source/DelayedTask.html#Ext-util.DelayedTask-method-cancel" class="viewSource">view source</a></div><a name="cancel"></a><a name="method-cancel"></a><a href="Ext.util.DelayedTask.html#" rel="method-cancel" class="cls expand">cancel</a> : void</div><div class="description"><div class="short"><p>Cancel the last queued timeout</p>
74 </div><div class="long"><p>Cancel the last queued timeout</p>
75 <h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
76 </li></ul></div></div></div><div id="method-delay" class="member ni"><a href="Ext.util.DelayedTask.html#method-delay" rel="method-delay" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.DelayedTask.html" class="definedIn docClass">Ext.util.DelayedTask</a><br/><a href="../source/DelayedTask.html#Ext-util.DelayedTask-method-delay" class="viewSource">view source</a></div><a name="delay"></a><a name="method-delay"></a><a href="Ext.util.DelayedTask.html#" rel="method-delay" class="cls expand">delay</a>(
77 <span class="pre">Number delay, [Function newFn], [Object newScope], [Array newArgs]</span>)
78  : void</div><div class="description"><div class="short"><p>Cancels any pending timeout and queues a new one</p>
79 </div><div class="long"><p>Cancels any pending timeout and queues a new one</p>
80 <h3 class="pa">Parameters</h3><ul><li><span class="pre">delay</span> : Number<div class="sub-desc"><p>The milliseconds to delay</p>
81 </div></li><li><span class="pre">newFn</span> : Function<div class="sub-desc"><p>(optional) Overrides function passed to constructor</p>
82 </div></li><li><span class="pre">newScope</span> : Object<div class="sub-desc"><p>(optional) Overrides scope passed to constructor. Remember that if no scope
83 is specified, <code>this</code> will refer to the browser window.</p>
84 </div></li><li><span class="pre">newArgs</span> : Array<div class="sub-desc"><p>(optional) Overrides args passed to constructor</p>
85 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
86 </li></ul></div></div></div></div></div></div></div><div id="pageContent"></div></div></div></div></body></html>