Debian Codegraph @

closure-library/closure/goog/dom/pattern/callback/counter.js

raw
1 // Copyright 2007 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /**
16 * @fileoverview Callback object that counts matches.
17 *
18 * @author [email protected] (Robby Walker)
19 */
20
21 goog.provide('goog.dom.pattern.callback.Counter');
22
23
24
25 /**
26 * Callback class for counting matches.
27 * @constructor
28 * @final
29 */
30 goog.dom.pattern.callback.Counter = function() {
31 /**
32 * The count of objects matched so far.
33 *
34 * @type {number}
35 */
36 this.count = 0;
37
38 /**
39 * The callback function. Suitable as a callback for
40 * {@link goog.dom.pattern.Matcher}.
41 * @private {Function}
42 */
43 this.callback_ = null;
44 };
45
46
47 /**
48 * Get a bound callback function that is suitable as a callback for
49 * {@link goog.dom.pattern.Matcher}.
50 *
51 * @return {!Function} A callback function.
52 */
53 goog.dom.pattern.callback.Counter.prototype.getCallback = function() {
54 if (!this.callback_) {
55 this.callback_ = goog.bind(function() {
56 this.count++;
57 return false;
58 }, this);
59 }
60 return this.callback_;
61 };
62
63
64 /**
65 * Reset the counter.
66 */
67 goog.dom.pattern.callback.Counter.prototype.reset = function() {
68 this.count = 0;
69 };