add Ox.once, fix docs

This commit is contained in:
rolux 2014-02-02 02:19:19 +05:30
parent 5a615730e9
commit 2077ea718a

View file

@ -59,8 +59,8 @@ Ox.cache = function(fn, options) {
}; };
/*@ /*@
Ox.debounce <f> Runs a function once it stops being called for a given time frame Ox.debounce <f> Runs a function once it stops being called for a given interval
(fn[, ms][, immediate]) -> <f> Throttled function (fn[, ms][, immediate]) -> <f> Debounced function
fn <f> Function to debounce fn <f> Function to debounce
ms <n|250> Interval in milliseconds ms <n|250> Interval in milliseconds
immediate <b|false> If true, function is called once immediately immediate <b|false> If true, function is called once immediately
@ -113,6 +113,21 @@ Ox.noop = function() {
Ox.isFunction(callback) && callback(); Ox.isFunction(callback) && callback();
}; };
/*@
Ox.once <f> Runs a function once, and then never again
(fn[, ms]) -> <f> Function that will run only once
fn <f> Function to run once
@*/
Ox.once = function(fn) {
var once = false;
return function() {
if (!once) {
once = true;
fn.apply(null, args);
}
};
};
/*@ /*@
Ox.queue <f> Queue of asynchronous function calls with cached results Ox.queue <f> Queue of asynchronous function calls with cached results
The results are cached based on all arguments to `fn`, except the last one, The results are cached based on all arguments to `fn`, except the last one,
@ -179,7 +194,7 @@ Ox.queue = function(fn, maxThreads) {
}; };
/*@ /*@
Ox.throttle <f> Runs a function at most once per given time frame Ox.throttle <f> Runs a function at most once per given interval
(fn[, ms]) -> <f> Throttled function (fn[, ms]) -> <f> Throttled function
fn <f> Function to throttle fn <f> Function to throttle
ms <n|250> Interval in milliseconds ms <n|250> Interval in milliseconds