| Index: third_party/google_input_tools/third_party/closure_library/closure/goog/functions/functions.js
|
| diff --git a/third_party/google_input_tools/third_party/closure_library/closure/goog/functions/functions.js b/third_party/google_input_tools/third_party/closure_library/closure/goog/functions/functions.js
|
| index 0c70f013834a3cf0280ab32833d758eeef867b88..670a7d5dfa62ef3799eec0f0df6f32b188fe9489 100644
|
| --- a/third_party/google_input_tools/third_party/closure_library/closure/goog/functions/functions.js
|
| +++ b/third_party/google_input_tools/third_party/closure_library/closure/goog/functions/functions.js
|
| @@ -127,7 +127,7 @@ goog.functions.nth = function(n) {
|
| * and replaces it with a new one.
|
| * @param {Function} f A function.
|
| * @param {T} retValue A new return value.
|
| - * @return {function(...[?]):T} A new function.
|
| + * @return {function(...?):T} A new function.
|
| * @template T
|
| */
|
| goog.functions.withReturnValue = function(f, retValue) {
|
| @@ -136,11 +136,29 @@ goog.functions.withReturnValue = function(f, retValue) {
|
|
|
|
|
| /**
|
| + * Creates a function that returns whether its arguement equals the given value.
|
| + *
|
| + * Example:
|
| + * var key = goog.object.findKey(obj, goog.functions.equalTo('needle'));
|
| + *
|
| + * @param {*} value The value to compare to.
|
| + * @param {boolean=} opt_useLooseComparison Whether to use a loose (==)
|
| + * comparison rather than a strict (===) one. Defaults to false.
|
| + * @return {function(*):boolean} The new function.
|
| + */
|
| +goog.functions.equalTo = function(value, opt_useLooseComparison) {
|
| + return function(other) {
|
| + return opt_useLooseComparison ? (value == other) : (value === other);
|
| + };
|
| +};
|
| +
|
| +
|
| +/**
|
| * Creates the composition of the functions passed in.
|
| * For example, (goog.functions.compose(f, g))(a) is equivalent to f(g(a)).
|
| - * @param {function(...[?]):T} fn The final function.
|
| + * @param {function(...?):T} fn The final function.
|
| * @param {...Function} var_args A list of functions.
|
| - * @return {function(...[?]):T} The composition of all inputs.
|
| + * @return {function(...?):T} The composition of all inputs.
|
| * @template T
|
| */
|
| goog.functions.compose = function(fn, var_args) {
|
| @@ -186,7 +204,7 @@ goog.functions.sequence = function(var_args) {
|
| * short-circuited as soon as a function returns false.
|
| * For example, (goog.functions.and(f, g))(x) is equivalent to f(x) && g(x).
|
| * @param {...Function} var_args A list of functions.
|
| - * @return {function(...[?]):boolean} A function that ANDs its component
|
| + * @return {function(...?):boolean} A function that ANDs its component
|
| * functions.
|
| */
|
| goog.functions.and = function(var_args) {
|
| @@ -209,7 +227,7 @@ goog.functions.and = function(var_args) {
|
| * short-circuited as soon as a function returns true.
|
| * For example, (goog.functions.or(f, g))(x) is equivalent to f(x) || g(x).
|
| * @param {...Function} var_args A list of functions.
|
| - * @return {function(...[?]):boolean} A function that ORs its component
|
| + * @return {function(...?):boolean} A function that ORs its component
|
| * functions.
|
| */
|
| goog.functions.or = function(var_args) {
|
| @@ -230,7 +248,7 @@ goog.functions.or = function(var_args) {
|
| * Creates a function that returns the Boolean opposite of a provided function.
|
| * For example, (goog.functions.not(f))(x) is equivalent to !f(x).
|
| * @param {!Function} f The original function.
|
| - * @return {function(...[?]):boolean} A function that delegates to f and returns
|
| + * @return {function(...?):boolean} A function that delegates to f and returns
|
| * opposite.
|
| */
|
| goog.functions.not = function(f) {
|
| @@ -244,17 +262,20 @@ goog.functions.not = function(f) {
|
| * Generic factory function to construct an object given the constructor
|
| * and the arguments. Intended to be bound to create object factories.
|
| *
|
| - * Callers should cast the result to the appropriate type for proper type
|
| - * checking by the compiler.
|
| - * @param {!Function} constructor The constructor for the Object.
|
| + * Example:
|
| + *
|
| + * var factory = goog.partial(goog.functions.create, Class);
|
| + *
|
| + * @param {function(new:T, ...)} constructor The constructor for the Object.
|
| * @param {...*} var_args The arguments to be passed to the constructor.
|
| - * @return {!Object} A new instance of the class given in {@code constructor}.
|
| + * @return {T} A new instance of the class given in {@code constructor}.
|
| + * @template T
|
| */
|
| goog.functions.create = function(constructor, var_args) {
|
| /**
|
| - * @constructor
|
| - * @final
|
| - */
|
| + * @constructor
|
| + * @final
|
| + */
|
| var temp = function() {};
|
| temp.prototype = constructor.prototype;
|
|
|
| @@ -309,3 +330,27 @@ goog.functions.cacheReturnValue = function(fn) {
|
| return value;
|
| }
|
| };
|
| +
|
| +
|
| +/**
|
| + * Wraps a function to allow it to be called, at most, once. All
|
| + * additional calls are no-ops.
|
| + *
|
| + * This is particularly useful for initialization functions
|
| + * that should be called, at most, once.
|
| + *
|
| + * @param {function():*} f Function to call.
|
| + * @return {function():undefined} Wrapped function.
|
| + */
|
| +goog.functions.once = function(f) {
|
| + // Keep a reference to the function that we null out when we're done with
|
| + // it -- that way, the function can be GC'd when we're done with it.
|
| + var inner = f;
|
| + return function() {
|
| + if (inner) {
|
| + var tmp = inner;
|
| + inner = null;
|
| + tmp();
|
| + }
|
| + };
|
| +};
|
|
|