cc.fovea.cordova.purchase
Version:
Cordova Purchase plugin for iOS, Android, Windows (AppStore, Play, UWP)
60 lines (51 loc) • 1.46 kB
JavaScript
(function() {
var isReady = false;
var callbacks = [];
/// ## <a name="ready"></a>*store.ready(callback)*
/// Register the `callback` to be called when the store is ready to be used.
///
/// If the store is already ready, `callback` is executed immediately.
///
/// `store.ready()` without arguments will return the `ready` status.
///
store.ready = function (cb) {
/// ### alternate usage (internal)
///
/// `store.ready(true)` will set the `ready` status to true,
/// and call the registered callbacks.
if (cb === true) {
if (isReady) return this;
isReady = true;
for (var i = 0; i < callbacks.length; ++i)
store.utils.callExternal('ready.callback', callbacks[i]);
callbacks = [];
}
else if (cb) {
if (isReady) {
// defer execution to prevent falsy belief that code works
// whereas it only works synchronously.
setTimeout(function() {
store.utils.callExternal('ready.callback', cb);
}, 1);
return this;
}
else {
callbacks.push(cb);
}
}
else {
return isReady;
}
return this;
};
// Remove any callbacks registered with `ready`
store.ready.unregister = function(cb) {
callbacks = callbacks.filter(function(o) {
return o !== cb;
});
};
store.ready.reset = function() {
isReady = false;
callbacks = [];
};
})();