You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ko...@apache.org on 2014/08/18 14:09:10 UTC
git commit: [OLINGO-408] add comments for datajs/store/*.js and other
files
Repository: olingo-odata4-js
Updated Branches:
refs/heads/master 0e57dcf17 -> b59d0b23d
[OLINGO-408] add comments for datajs/store/*.js and other files
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/commit/b59d0b23
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/tree/b59d0b23
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/diff/b59d0b23
Branch: refs/heads/master
Commit: b59d0b23d417f8b1809e0a8f214681abcbf2112e
Parents: 0e57dcf
Author: Sven Kobler <sv...@sap.com>
Authored: Mon Aug 18 14:08:56 2014 +0200
Committer: Sven Kobler <sv...@sap.com>
Committed: Mon Aug 18 14:08:56 2014 +0200
----------------------------------------------------------------------
datajs/src/lib/datajs.js | 1 -
datajs/src/lib/datajs/deferred.js | 5 +-
datajs/src/lib/datajs/utils.js | 197 +++++++++++++++++----------------
datajs/src/lib/store.js | 2 +
datajs/src/lib/store/dom.js | 79 ++++++-------
datajs/src/lib/store/indexeddb.js | 48 +++++---
datajs/src/lib/store/memory.js | 71 ++++++------
7 files changed, 215 insertions(+), 188 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/b59d0b23/datajs/src/lib/datajs.js
----------------------------------------------------------------------
diff --git a/datajs/src/lib/datajs.js b/datajs/src/lib/datajs.js
index 88ed102..6803f5f 100644
--- a/datajs/src/lib/datajs.js
+++ b/datajs/src/lib/datajs.js
@@ -25,7 +25,6 @@ exports.version = {
build: 1
};
-
exports.deferred = require('./datajs/deferred.js');
exports.utils = require('./datajs/utils.js');
exports.xml = require('./datajs/xml.js');
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/b59d0b23/datajs/src/lib/datajs/deferred.js
----------------------------------------------------------------------
diff --git a/datajs/src/lib/datajs/deferred.js b/datajs/src/lib/datajs/deferred.js
index 3b74b94..ac06820 100644
--- a/datajs/src/lib/datajs/deferred.js
+++ b/datajs/src/lib/datajs/deferred.js
@@ -21,6 +21,7 @@
/** createDeferred (see {@link createDeferred}) */
exports.createDeferred = createDeferred;
+
/** DjsDeferred (see {@link DjsDeferred}) */
exports.DjsDeferred = DjsDeferred;
@@ -62,13 +63,13 @@ function forwardCall(thisValue, name, returnValue) {
* </li></ul>
* @class DjsDeferred
*/
-var DjsDeferred = function () {
+ function DjsDeferred() {
this._arguments = undefined;
this._done = undefined;
this._fail = undefined;
this._resolved = false;
this._rejected = false;
-};
+}
DjsDeferred.prototype = {
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/b59d0b23/datajs/src/lib/datajs/utils.js
----------------------------------------------------------------------
diff --git a/datajs/src/lib/datajs/utils.js b/datajs/src/lib/datajs/utils.js
index 6a98408..cf586db 100644
--- a/datajs/src/lib/datajs/utils.js
+++ b/datajs/src/lib/datajs/utils.js
@@ -17,6 +17,37 @@
* under the License.
*/
+/** @module datajs/utils */
+
+exports.activeXObject = activeXObject;
+exports.assigned = assigned;
+exports.contains = contains;
+exports.defined = defined;
+exports.delay = delay;
+exports.djsassert = djsassert;
+exports.extend = extend;
+exports.find = find;
+exports.getURIInfo = getURIInfo;
+exports.isArray = isArray;
+exports.isDate = isDate;
+exports.isObject = isObject;
+exports.normalizeURI = normalizeURI;
+exports.normalizeURICase = normalizeURICase;
+exports.parseInt10 = parseInt10;
+exports.renameProperty = renameProperty;
+exports.throwErrorCallback = throwErrorCallback;
+exports.trimString = trimString;
+exports.undefinedDefault = undefinedDefault;
+exports.decodeBase64 = decodeBase64;
+exports.convertByteArrayToHexString = convertByteArrayToHexString;
+exports.getJsonValueArraryLength = getJsonValueArraryLength;
+exports.sliceJsonValueArray = sliceJsonValueArray;
+exports.concatJsonValueArray = concatJsonValueArray;
+exports.startsWith = startsWith;
+exports.endsWith = endsWith;
+exports.getFormatKind = getFormatKind;
+
+
/** Creates a new ActiveXObject from the given progId.
* @param {String} progId - ProgId string of the desired ActiveXObject.
* @returns {Object} The ActiveXObject instance. Null if ActiveX is not supported by the browser.
@@ -35,16 +66,16 @@ var activeXObject = function (progId) {
* @param [value] Value to check ( may be null)
* @returns {Boolean} true if the value is assigned; false otherwise.
*/
-var assigned = function (value) {
+function assigned(value) {
return value !== null && value !== undefined;
-};
+}
/** Checks whether the specified item is in the array.
* @param {Array} [arr] Array to check in.
* @param item - Item to look for.
* @returns {Boolean} true if the item is contained, false otherwise.
*/
-var contains = function (arr, item) {
+function contains(arr, item) {
var i, len;
for (i = 0, len = arr.length; i < len; i++) {
if (arr[i] === item) {
@@ -52,22 +83,21 @@ var contains = function (arr, item) {
}
}
return false;
-};
+}
/** Given two values, picks the first one that is not undefined.
* @param a - First value.
* @param b - Second value.
* @returns a if it's a defined value; else b.</returns>
*/
-var defined = function (a, b) {
-
+function defined(a, b) {
return (a !== undefined) ? a : b;
-};
+}
/** Delays the invocation of the specified function until execution unwinds.
* @param {Function} callback - Callback function.
*/
-var delay = function (callback) {
+function delay(callback) {
if (arguments.length === 1) {
window.setTimeout(callback, 0);
@@ -78,7 +108,7 @@ var delay = function (callback) {
window.setTimeout(function () {
callback.apply(this, args);
}, 0);
-};
+}
/** Throws an exception in case that a condition evaluates to false.
* @param {Boolean} condition - Condition to evaluate.
@@ -86,13 +116,13 @@ var delay = function (callback) {
* @param {Object} data - Additional data to be included in the exception.
*/
// DATAJS INTERNAL START
-var djsassert = function (condition, message, data) {
+function djsassert(condition, message, data) {
if (!condition) {
throw { message: "Assert fired: " + message, data: data };
- };
-};
+ }
+}
// DATAJS INTERNAL END
/** Extends the target with the specified values.
@@ -100,15 +130,15 @@ var djsassert = function (condition, message, data) {
* @param {Object} values - Object with properties to add into target.
* @returns {Object} The target object.
*/
-var extend = function (target, values) {
+function extend(target, values) {
for (var name in values) {
target[name] = values[name];
}
return target;
-};
+}
-var find = function (arr, callback) {
+function find(arr, callback) {
/** Returns the first item in the array that makes the callback function true.
* @param {Array} [arr] Array to check in. ( may be null)
* @param {Function} callback - Callback function to invoke once per item in the array.
@@ -124,42 +154,41 @@ var find = function (arr, callback) {
}
}
return null;
-};
+}
-var isArray = function (value) {
+function isArray(value) {
/** Checks whether the specified value is an array object.
* @param value - Value to check.
* @returns {Boolean} true if the value is an array object; false otherwise.
*/
return Object.prototype.toString.call(value) === "[object Array]";
-};
+}
/** Checks whether the specified value is a Date object.
* @param value - Value to check.
* @returns {Boolean} true if the value is a Date object; false otherwise.
*/
-var isDate = function (value) {
+function isDate(value) {
return Object.prototype.toString.call(value) === "[object Date]";
-};
+}
/** Tests whether a value is an object.
* @param value - Value to test.
* @returns {Boolean} True is the value is an object; false otherwise.
* Per javascript rules, null and array values are objects and will cause this function to return true.
*/
-var isObject = function (value) {
-
+function isObject(value) {
return typeof value === "object";
-};
+}
/** Parses a value in base 10.
* @param {String} value - String value to parse.
* @returns {Number} The parsed value, NaN if not a valid value.
*/
-var parseInt10 = function (value) {
+function parseInt10(value) {
return parseInt(value, 10);
-};
+}
/** Renames a property in an object.
* @param {Object} obj - Object in which the property will be renamed.
@@ -167,31 +196,31 @@ var parseInt10 = function (value) {
* @param {String} newName - New name of the property.
* This function will not do anything if the object doesn't own a property with the specified old name.
*/
-var renameProperty = function (obj, oldName, newName) {
+function renameProperty(obj, oldName, newName) {
if (obj.hasOwnProperty(oldName)) {
obj[newName] = obj[oldName];
delete obj[oldName];
}
-};
+}
/** Default error handler.
* @param {Object} error - Error to handle.
*/
-var throwErrorCallback = function (error) {
+function throwErrorCallback(error) {
throw error;
-};
+}
/** Removes leading and trailing whitespaces from a string.
* @param {String str String to trim
* @returns {String} The string with no leading or trailing whitespace.
*/
-var trimString = function (str) {
+function trimString(str) {
if (str.trim) {
return str.trim();
}
return str.replace(/^\s+|\s+$/g, '');
-};
+}
/** Returns a default value in place of undefined.
* @param [value] Value to check (may be null)
@@ -200,9 +229,9 @@ var trimString = function (str) {
* This should only be used for cases where falsy values are valid;
* otherwise the pattern should be 'x = (value) ? value : defaultValue;'.
*/
-var undefinedDefault = function (value, defaultValue) {
+function undefinedDefault(value, defaultValue) {
return (value !== undefined) ? value : defaultValue;
-};
+}
// Regular expression that splits a uri into its components:
// 0 - is the matched string.
@@ -218,7 +247,7 @@ var uriPartNames = ["scheme", "authority", "path", "query", "fragment"];
* @param {String} uri - URI to get information from.
* @return {Object} An object with an isAbsolute flag and part names (scheme, authority, etc.) if available.
*/
-var getURIInfo = function (uri) {
+function getURIInfo(uri) {
var result = { isAbsolute: false };
if (uri) {
@@ -237,20 +266,20 @@ var getURIInfo = function (uri) {
}
return result;
-};
+}
/** Builds a URI string from its components.
* @param {Object} uriInfo - An object with uri parts (scheme, authority, etc.).
* @returns {String} URI string.
*/
-var getURIFromInfo = function (uriInfo) {
+function getURIFromInfo(uriInfo) {
return "".concat(
uriInfo.scheme || "",
uriInfo.authority || "",
uriInfo.path || "",
uriInfo.query || "",
uriInfo.fragment || "");
-};
+}
// Regular expression that splits a uri authority into its subcomponents:
// 0 - is the matched string.
@@ -266,7 +295,7 @@ var pctEncodingRegEx = /%[0-9A-F]{2}/ig;
* @param {String} uri - URI to normalize, absolute or relative.
* @returns {String} The URI normalized to lower case.
*/
-var normalizeURICase = function (uri) {
+function normalizeURICase(uri) {
var uriInfo = getURIInfo(uri);
var scheme = uriInfo.scheme;
var authority = uriInfo.authority;
@@ -289,14 +318,14 @@ var normalizeURICase = function (uri) {
return uri.replace(pctEncodingRegEx, function (str) {
return str.toLowerCase();
});
-};
+}
/** Normalizes a possibly relative URI with a base URI.
* @param {String} uri - URI to normalize, absolute or relative
* @param {String} base - Base URI to compose with (may be null)
* @returns {String} The composed URI if relative; the original one if absolute.
*/
-var normalizeURI = function (uri, base) {
+function normalizeURI(uri, base) {
if (!base) {
return uri;
}
@@ -335,14 +364,14 @@ var normalizeURI = function (uri, base) {
normInfo.fragment = uriInfo.fragment;
return getURIFromInfo(normInfo);
-};
+}
/** Merges the path of a relative URI and a base URI.
* @param {String} uriPath - Relative URI path.</param>
* @param {String} basePath - Base URI path.
* @returns {String} A string with the merged path.
*/
-var mergeUriPathWithBase = function (uriPath, basePath) {
+function mergeUriPathWithBase(uriPath, basePath) {
var path = "/";
var end;
@@ -356,13 +385,13 @@ var mergeUriPathWithBase = function (uriPath, basePath) {
}
return path + uriPath;
-};
+}
/** Removes the special folders . and .. from a URI's path.
* @param {string} path - URI path component.
* @returns {String} Path without any . and .. folders.
*/
-var removeDotsFromPath = function (path) {
+function removeDotsFromPath(path) {
var result = "";
var segment = "";
var end;
@@ -391,9 +420,9 @@ var removeDotsFromPath = function (path) {
}
}
return result;
-};
+}
-var convertByteArrayToHexString = function (str) {
+function convertByteArrayToHexString(str) {
var arr = [];
if (window.atob === undefined) {
arr = decodeBase64(str);
@@ -411,9 +440,9 @@ var convertByteArrayToHexString = function (str) {
hexValue += hexValues[t & 0x0F];
}
return hexValue;
-};
+}
-var decodeBase64 = function (str) {
+function decodeBase64(str) {
var binaryString = "";
for (var i = 0; i < str.length; i++) {
var base65IndexValue = getBase64IndexValue(str[i]);
@@ -430,9 +459,9 @@ var decodeBase64 = function (str) {
byteArray.push(intValue);
}
return byteArray;
-};
+}
-var getBase64IndexValue = function (character) {
+function getBase64IndexValue(character) {
var asciiCode = character.charCodeAt(0);
var asciiOfA = 65;
var differenceBetweenZanda = 6;
@@ -449,26 +478,26 @@ var getBase64IndexValue = function (character) {
} else {
return null;
}
-};
+}
-var addBase64Padding = function (binaryString) {
+function addBase64Padding(binaryString) {
while (binaryString.length < 6) {
binaryString = "0" + binaryString;
}
return binaryString;
-};
+}
-var getJsonValueArraryLength = function (data) {
+function getJsonValueArraryLength(data) {
if (data && data.value) {
return data.value.length;
}
return 0;
-};
+}
-var sliceJsonValueArray = function (data, start, end) {
- if (data == undefined || data.value == undefined) {
+function sliceJsonValueArray(data, start, end) {
+ if (data === undefined || data.value === undefined) {
return data;
}
@@ -491,18 +520,18 @@ var sliceJsonValueArray = function (data, start, end) {
}
return newdata;
-};
+}
-var concatJsonValueArray = function (data, concatData) {
- if (concatData == undefined || concatData.value == undefined) {
+function concatJsonValueArray(data, concatData) {
+ if (concatData === undefined || concatData.value === undefined) {
return data;
}
- if (data == undefined || Object.keys(data).length == 0) {
+ if (data === undefined || Object.keys(data).length === 0) {
return concatData;
}
- if (data.value == undefined) {
+ if (data.value === undefined) {
data.value = concatData.value;
return data;
}
@@ -510,17 +539,17 @@ var concatJsonValueArray = function (data, concatData) {
data.value = data.value.concat(concatData.value);
return data;
-};
+}
-var endsWith = function (input, search) {
+function endsWith(input, search) {
return input.indexOf(search, input.length - search.length) !== -1;
-};
+}
-var startsWith = function (input, search) {
- return input.indexOf(search) == 0;
-};
+function startsWith (input, search) {
+ return input.indexOf(search) === 0;
+}
-var getFormatKind = function (format, defaultFormatKind) {
+function getFormatKind(format, defaultFormatKind) {
var formatKind = defaultFormatKind;
if (!assigned(format)) {
return formatKind;
@@ -542,33 +571,7 @@ var getFormatKind = function (format, defaultFormatKind) {
}
return formatKind;
-};
+}
+
-exports.activeXObject = activeXObject;
-exports.assigned = assigned;
-exports.contains = contains;
-exports.defined = defined;
-exports.delay = delay;
-exports.djsassert = djsassert;
-exports.extend = extend;
-exports.find = find;
-exports.getURIInfo = getURIInfo;
-exports.isArray = isArray;
-exports.isDate = isDate;
-exports.isObject = isObject;
-exports.normalizeURI = normalizeURI;
-exports.normalizeURICase = normalizeURICase;
-exports.parseInt10 = parseInt10;
-exports.renameProperty = renameProperty;
-exports.throwErrorCallback = throwErrorCallback;
-exports.trimString = trimString;
-exports.undefinedDefault = undefinedDefault;
-exports.decodeBase64 = decodeBase64;
-exports.convertByteArrayToHexString = convertByteArrayToHexString;
-exports.getJsonValueArraryLength = getJsonValueArraryLength;
-exports.sliceJsonValueArray = sliceJsonValueArray;
-exports.concatJsonValueArray = concatJsonValueArray;
-exports.startsWith = startsWith;
-exports.endsWith = endsWith;
-exports.getFormatKind = getFormatKind;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/b59d0b23/datajs/src/lib/store.js
----------------------------------------------------------------------
diff --git a/datajs/src/lib/store.js b/datajs/src/lib/store.js
index 7e9263a..e96289d 100644
--- a/datajs/src/lib/store.js
+++ b/datajs/src/lib/store.js
@@ -17,6 +17,8 @@
* under the License.
*/
+ /** @module store */
+
exports.DomStore = DomStore = require('./store/dom.js');
exports.IndexedDBStore = IndexedDBStore = require('./store/indexeddb.js');
exports.MemoryStore = MemoryStore = require('./store/memory.js');
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/b59d0b23/datajs/src/lib/store/dom.js
----------------------------------------------------------------------
diff --git a/datajs/src/lib/store/dom.js b/datajs/src/lib/store/dom.js
index e9b09f3..686c046 100644
--- a/datajs/src/lib/store/dom.js
+++ b/datajs/src/lib/store/dom.js
@@ -17,6 +17,11 @@
* under the License.
*/
+/** @module store/dom */
+
+/** DomStore (see {@link DomStore}) */
+module.exports = DomStore;
+
var utils = require('./../datajs.js').utils;
// Imports.
@@ -25,34 +30,27 @@ var delay = utils.delay;
var localStorage = null;
-/** Converts a Date object into an object representation friendly to JSON serialization.
- * @returns {Object} Object that represents the Date.
-
- * This method is used to override the Date.toJSON method and is called only by
+/** This method is used to override the Date.toJSON method and is called only by
* JSON.stringify. It should never be called directly.
+ * @summary Converts a Date object into an object representation friendly to JSON serialization.
+ * @returns {Object} Object that represents the Date.
*/
-var domStoreDateToJSON = function () {
-
-
+function domStoreDateToJSON() {
var newValue = { v: this.valueOf(), t: "[object Date]" };
// Date objects might have extra properties on them so we save them.
for (var name in this) {
newValue[name] = this[name];
}
return newValue;
-};
+}
-/** JSON reviver function for converting an object representing a Date in a JSON stream to a Date object
+/** This method is used during JSON parsing and invoked only by the reviver function.
+ * It should never be called directly.
+ * @summary JSON reviver function for converting an object representing a Date in a JSON stream to a Date object
* @param Object - Object to convert.
* @returns {Date} Date object.
- * This method is used during JSON parsing and invoked only by the reviver function.
- * It should never be called directly.
*/
-var domStoreJSONToDate = function (_, value) {
-
-
-
-
+function domStoreJSONToDate(_, value) {
if (value && value.t === "[object Date]") {
var newValue = new Date(value.v);
for (var name in value) {
@@ -63,36 +61,36 @@ var domStoreJSONToDate = function (_, value) {
value = newValue;
}
return value;
-};
+}
/** Qualifies the key with the name of the store.
* @param {Object} store - Store object whose name will be used for qualifying the key.
* @param {String} key - Key string.
* @returns {String} Fully qualified key string.
*/
-var qualifyDomStoreKey = function (store, key) {
-
+function qualifyDomStoreKey(store, key) {
return store.name + "#!#" + key;
-};
+}
/** Gets the key part of a fully qualified key string.
* @param {Object} store - Store object whose name will be used for qualifying the key.
* @param {String} key - Fully qualified key string.
* @returns {String} Key part string
*/
-var unqualifyDomStoreKey = function (store, key) {
-
+function unqualifyDomStoreKey(store, key) {
return key.replace(store.name + "#!#", "");
-};
+}
/** Constructor for store objects that use DOM storage as the underlying mechanism.
+ * @class DomStore
* @param {String} name - Store name.
*/
-var DomStore = function (name) {
+function DomStore(name) {
this.name = name;
-};
+}
/** Creates a store object that uses DOM Storage as its underlying mechanism.
+ * @method DomStore.create
* @param {String} name - Store name.
* @returns {Object} Store object.
*/
@@ -107,6 +105,7 @@ DomStore.create = function (name) {
};
/** Checks whether the underlying mechanism for this kind of store objects is supported by the browser.
+ * @method DomStore.isSupported
* @returns {Boolean} - True if the mechanism is supported by the browser; otherwise false.
*/
DomStore.isSupported = function () {
@@ -114,6 +113,7 @@ DomStore.isSupported = function () {
};
/** Adds a new value identified by a key to the store.
+ * @method DomStore#add
* @param {String} key - Key string.
* @param value - Value that is going to be added to the store.
* @param {Funcktion} success - Callback for a successful add operation.</param>
@@ -121,8 +121,6 @@ DomStore.isSupported = function () {
* This method errors out if the store already contains the specified key.
*/
DomStore.prototype.add = function (key, value, success, error) {
-
-
error = error || this.defaultError;
var store = this;
this.contains(key, function (contained) {
@@ -134,17 +132,15 @@ DomStore.prototype.add = function (key, value, success, error) {
}, error);
};
-/** Adds or updates a value identified by a key to the store.
+/** This method will overwrite the key's current value if it already exists in the store; otherwise it simply adds the new key and value.
+ * @summary Adds or updates a value identified by a key to the store.
+ * @method DomStore#addOrUpdate
* @param {String} key - Key string.
* @param value - Value that is going to be added or updated to the store.
* @param {Function} success - Callback for a successful add or update operation.</param>
* @param {Function} [error] - Callback for handling errors. If not specified then store.defaultError is invoked.</param>
-
- * This method will overwrite the key's current value if it already exists in the store; otherwise it simply adds the new key and value.
- */
+ */
DomStore.prototype.addOrUpdate = function (key, value, success, error) {
-
-
error = error || this.defaultError;
if (key instanceof Array) {
@@ -176,10 +172,11 @@ DomStore.prototype.addOrUpdate = function (key, value, success, error) {
}
};
-/** Removes all the data associated with this store object.
+/** In case of an error, this method will not restore any keys that might have been deleted at that point.
+ * @summary Removes all the data associated with this store object.
+ * @method DomStore#clear
* @param {Function} success - Callback for a successful clear operation.</param>
* @param {Function} [error] - Callback for handling errors. If not specified then store.defaultError is invoked.</param>
- * In case of an error, this method will not restore any keys that might have been deleted at that point.
*/
DomStore.prototype.clear = function (success, error) {
@@ -204,11 +201,13 @@ DomStore.prototype.clear = function (success, error) {
};
/** This function does nothing in DomStore as it does not have a connection model
-*/
+ * @method DomStore#close
+ */
DomStore.prototype.close = function () {
};
/** Checks whether a key exists in the store.
+ * @method DomStore#contains
* @param {String} key - Key string.
* @param {Function} success - Callback indicating whether the store contains the key or not.</param>
* @param {Function} [error] - Callback for handling errors. If not specified then store.defaultError is invoked.</param>
@@ -227,6 +226,7 @@ DomStore.prototype.contains = function (key, success, error) {
DomStore.prototype.defaultError = throwErrorCallback;
/** Gets all the keys that exist in the store.
+ * @method DomStore#getAllKeys
* @param {Function} success - Callback for a successful get operation.</param>
* @param {Function} [error] - Callback for handling errors. If not specified then store.defaultError is invoked.</param>
*/
@@ -256,6 +256,7 @@ DomStore.prototype.getAllKeys = function (success, error) {
DomStore.prototype.mechanism = "dom";
/** Reads the value associated to a key in the store.
+ * @method DomStore#read
* @param {String} key - Key string.
* @param {Function} success - Callback for a successful reads operation.
* @param {Function} [error] - Callback for handling errors. If not specified then store.defaultError is invoked.
@@ -285,6 +286,7 @@ DomStore.prototype.read = function (key, success, error) {
};
/** Removes a key and its value from the store.
+ * @method DomStore#remove
* @param {String} key - Key string.
* @param {Funtion} success - Callback for a successful remove operation.</param>
* @param {Funtion} [error] - Callback for handling errors. If not specified then store.defaultError is invoked.</param>
@@ -306,6 +308,7 @@ DomStore.prototype.remove = function (key, success, error) {
};
/** Updates the value associated to a key in the store.
+ * @method DomStore#update
* @param {String} key - Key string.
* @param value - New value.
* @param {Function} success - Callback for a successful update operation.
@@ -313,8 +316,6 @@ DomStore.prototype.remove = function (key, success, error) {
* This method errors out if the specified key is not found in the store.
*/
DomStore.prototype.update = function (key, value, success, error) {
-
-
error = error || this.defaultError;
var store = this;
this.contains(key, function (contained) {
@@ -326,4 +327,4 @@ DomStore.prototype.update = function (key, value, success, error) {
}, error);
};
-module.exports = DomStore;
+
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/b59d0b23/datajs/src/lib/store/indexeddb.js
----------------------------------------------------------------------
diff --git a/datajs/src/lib/store/indexeddb.js b/datajs/src/lib/store/indexeddb.js
index 1570dd6..b66a895 100644
--- a/datajs/src/lib/store/indexeddb.js
+++ b/datajs/src/lib/store/indexeddb.js
@@ -17,8 +17,12 @@
* under the License.
*/
-var utils = require('./../datajs.js').utils;
+/** @module store/indexeddb */
+
+/** IndexedDBStore (see {@link IndexedDBStore}) */
+module.exports = IndexedDBStore;
+var utils = require('./../datajs.js').utils;
// Imports.
var throwErrorCallback = utils.throwErrorCallback;
@@ -36,7 +40,7 @@ var IDBT_READ_WRITE = IDBTransaction.READ_WRITE || "readwrite";
* @param {Function} defaultError - The default error handler
* @returns {Function} The error callback
*/
-var getError = function (error, defaultError) {
+function getError(error, defaultError) {
return function (e) {
var errorFunc = error || defaultError;
@@ -63,14 +67,14 @@ var getError = function (error, defaultError) {
}
errorFunc({ name: errName, error: e });
};
-};
+}
/** Opens the store object's indexed db database.
* @param {IndexedDBStore} store - The store object
* @param {Function} success - The success callback
* @param {Function} error - The error callback
*/
-var openStoreDb = function (store, success, error) {
+function openStoreDb(store, success, error) {
var storeName = store.name;
var dbName = "_datajs_" + storeName;
@@ -117,7 +121,7 @@ var openStoreDb = function (store, success, error) {
};
success(db);
};
-};
+}
/** Opens a new transaction to the store
* @param {IndexedDBStore} store - The store object
@@ -125,7 +129,7 @@ var openStoreDb = function (store, success, error) {
* @param {Function} success - The success callback
* @param {Function} error - The error callback
*/
-var openTransaction = function (store, mode, success, error) {
+function openTransaction(store, mode, success, error) {
var storeName = store.name;
var storeDb = store.db;
@@ -140,17 +144,19 @@ var openTransaction = function (store, mode, success, error) {
store.db = db;
success(db.transaction(storeName, mode));
}, errorCallback);
-};
+}
/** Creates a new IndexedDBStore.
+ * @class IndexedDBStore
* @param {String} name - The name of the store.
* @returns {Object} The new IndexedDBStore.
*/
-var IndexedDBStore = function (name) {
+function IndexedDBStore(name) {
this.name = name;
-};
+}
/** Creates a new IndexedDBStore.
+ * @method IndexedDBStore.create
* @param {String} name - The name of the store.
* @returns {Object} The new IndexedDBStore.
*/
@@ -163,6 +169,7 @@ IndexedDBStore.create = function (name) {
};
/** Returns whether IndexedDB is supported.
+ * @method IndexedDBStore.isSupported
* @returns {Boolean} True if IndexedDB is supported, false otherwise.
*/
IndexedDBStore.isSupported = function () {
@@ -170,6 +177,7 @@ IndexedDBStore.isSupported = function () {
};
/** Adds a key/value pair to the store
+ * @method IndexedDBStore#add
* @param {String} key - The key
* @param {Object} value - The value
* @param {Function} success - The success callback
@@ -206,6 +214,7 @@ IndexedDBStore.prototype.add = function (key, value, success, error) {
};
/** Adds or updates a key/value pair in the store
+ * @method IndexedDBStore#addOrUpdate
* @param {String} key - The key
* @param {Object} value - The value
* @param {Function} success - The success callback
@@ -243,6 +252,7 @@ IndexedDBStore.prototype.addOrUpdate = function (key, value, success, error) {
};
/** Clears the store
+ * @method IndexedDBStore#clear
* @param {Function} success - The success callback
* @param {Function} error - The error callback
*/
@@ -258,10 +268,11 @@ IndexedDBStore.prototype.clear = function (success, error) {
transaction.objectStore(name).clear();
}, error);
};
-
+/** Closes the connection to the database
+ * @method IndexedDBStore#close
+*/
IndexedDBStore.prototype.close = function () {
- /** Closes the connection to the database
- */
+
if (this.db) {
this.db.close();
this.db = null;
@@ -269,6 +280,7 @@ IndexedDBStore.prototype.close = function () {
};
/** Returns whether the store contains a key
+ * @method IndexedDBStore#contains
* @param {String} key - The key
* @param {Function} success - The success callback
* @param {Function} error - The error callback
@@ -278,7 +290,7 @@ IndexedDBStore.prototype.contains = function (key, success, error) {
var defaultError = this.defaultError;
openTransaction(this, IDBT_READ_ONLY, function (transaction) {
var objectStore = transaction.objectStore(name);
- var request = objectStore["get"](key);
+ var request = objectStore.get(key);
transaction.oncomplete = function () {
success(!!request.result);
@@ -290,6 +302,7 @@ IndexedDBStore.prototype.contains = function (key, success, error) {
IndexedDBStore.prototype.defaultError = throwErrorCallback;
/** Gets all the keys from the store
+ * @method IndexedDBStore#getAllKeys
* @param {Function} success - The success callback
* @param {Function} error - The error callback
*/
@@ -322,6 +335,7 @@ IndexedDBStore.prototype.getAllKeys = function (success, error) {
IndexedDBStore.prototype.mechanism = "indexeddb";
/** Reads the value for the specified key
+ * @method IndexedDBStore#read
* @param {String} key - The key
* @param {Function} success - The success callback
* @param {Function} error - The error callback
@@ -347,7 +361,7 @@ IndexedDBStore.prototype.read = function (key, success, error) {
for (var i = 0; i < keys.length; i++) {
// Some tools have issues because get is a javascript reserved word.
var objectStore = transaction.objectStore(name);
- var request = objectStore["get"].call(objectStore, keys[i]);
+ var request = objectStore.get.call(objectStore, keys[i]);
request.onsuccess = function (event) {
var record = event.target.result;
values.push(record ? record.v : undefined);
@@ -357,6 +371,7 @@ IndexedDBStore.prototype.read = function (key, success, error) {
};
/** Removes the specified key from the store
+ * @method IndexedDBStore#remove
* @param {String} key - The key
* @param {Function} success - The success callback
* @param {Function} error - The error callback
@@ -382,6 +397,7 @@ IndexedDBStore.prototype.remove = function (key, success, error) {
};
/** Updates a key/value pair in the store
+ * @method IndexedDBStore#update
* @param {String} key - The key
* @param {Object} value - The value
* @param {Function} success - The success callback
@@ -422,9 +438,9 @@ IndexedDBStore.prototype.update = function (key, value, success, error) {
} else {
transaction.abort();
}
- };
+ }
}
}, error);
};
-module.exports = IndexedDBStore;
+
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/b59d0b23/datajs/src/lib/store/memory.js
----------------------------------------------------------------------
diff --git a/datajs/src/lib/store/memory.js b/datajs/src/lib/store/memory.js
index e91902f..ac7dc80 100644
--- a/datajs/src/lib/store/memory.js
+++ b/datajs/src/lib/store/memory.js
@@ -17,17 +17,22 @@
* under the License.
*/
-var utils = require('./../datajs.js').utils;
+ /** @module store/memory */
+
+/** MemoryStore (see {@link MemoryStore}) */
+module.exports = MemoryStore;
+var utils = require('./../datajs.js').utils;
// Imports.
var throwErrorCallback = utils.throwErrorCallback;
var delay = utils.delay;
/** Constructor for store objects that use a sorted array as the underlying mechanism.
+ * @class MemoryStore
* @param {String} name - Store name.
*/
-var MemoryStore = function (name) {
+function MemoryStore(name) {
var holes = [];
var items = [];
@@ -44,7 +49,7 @@ var MemoryStore = function (name) {
* @param {Function} error - Error callback.
* @returns {Boolean} True if the key is valid. False if the key is invalid and the error callback has been queued for execution.
*/
- var validateKeyInput = function (key, error) {
+ function validateKeyInput(key, error) {
var messageString;
@@ -61,15 +66,15 @@ var MemoryStore = function (name) {
return false;
}
return true;
- };
+ }
- /** Adds a new value identified by a key to the store.
+ /** This method errors out if the store already contains the specified key.
+ * @summery Adds a new value identified by a key to the store.
+ * @method MemoryStore#add
* @param {String} key - Key string.
* @param value - Value that is going to be added to the store.
* @param {Function} success - Callback for a successful add operation.</param>
* @param {Function} error - Callback for handling errors. If not specified then store.defaultError is invoked.</param>
-
- * This method errors out if the store already contains the specified key.
*/
this.add = function (key, value, success, error) {
error = getErrorCallback(error);
@@ -83,18 +88,16 @@ var MemoryStore = function (name) {
}
};
+ /** This method will overwrite the key's current value if it already exists in the store; otherwise it simply adds the new key and value.
+ * @summary Adds or updates a value identified by a key to the store.
+ * @method MemoryStore#addOrUpdate
+ * @param {String} key - Key string.
+ * @param value - Value that is going to be added or updated to the store.
+ * @param {Function} success - Callback for a successful add or update operation.</param>
+ * @param {Function} [error] - Callback for handling errors. If not specified then store.defaultError is invoked.</param>
+ */
this.addOrUpdate = function (key, value, success, error) {
- /** Adds or updates a value identified by a key to the store.
- * @param {String} key - Key string.
- * @param value - Value that is going to be added or updated to the store.
- *@param {Function} success - Callback for a successful add or update operation.</param>
- *@param {Function} [error] - Callback for handling errors. If not specified then store.defaultError is invoked.</param>
-
- This method will overwrite the key's current value if it already exists in the store; otherwise it simply adds the new key and value.
-
- */
-
error = getErrorCallback(error);
if (validateKeyInput(key, error)) {
@@ -112,29 +115,29 @@ var MemoryStore = function (name) {
}
};
+ /** Removes all the data associated with this store object.
+ * @method MemoryStore#clear
+ * @param {Function} success>Callback for a successful clear operation.
+ */
this.clear = function (success) {
- /** Removes all the data associated with this store object.
- * @param {Function} success>Callback for a successful clear operation.
- */
-
items = [];
keys = {};
holes = [];
-
delay(success);
};
/** Checks whether a key exists in the store.
+ * @method MemoryStore#contains
* @param {String} key - Key string.
* @param {Funktion} success - Callback indicating whether the store contains the key or not.</param>
*/
this.contains = function (key, success) {
-
var contained = keys.hasOwnProperty(key);
delay(success, contained);
};
/** Gets all the keys that exist in the store.
+ * @method MemoryStore#getAllKeys
* @param {Function} success - Callback for a successful get operation.</param>
*/
this.getAllKeys = function (success) {
@@ -147,6 +150,7 @@ var MemoryStore = function (name) {
};
/** Reads the value associated to a key in the store.
+ * @method MemoryStore#read
* @param {String} key - Key string.
* @param {Function} Function - Callback for a successful reads operation.</param>
* @param {Function{}Function - Callback for handling errors. If not specified then store.defaultError is invoked.</param>
@@ -160,11 +164,12 @@ var MemoryStore = function (name) {
}
};
-/** Removes a key and its value from the store.
- * @param {String} key - Key string.
- * @param {Function} success - Callback for a successful remove operation.</param>
- * @param {Function} [error] - Callback for handling errors. If not specified then store.defaultError is invoked.</param>
-*/
+ /** Removes a key and its value from the store.
+ * @method MemoryStore#remove
+ * @param {String} key - Key string.
+ * @param {Function} success - Callback for a successful remove operation.</param>
+ * @param {Function} [error] - Callback for handling errors. If not specified then store.defaultError is invoked.</param>
+ */
this.remove = function (key, success, error) {
error = getErrorCallback(error);
@@ -190,16 +195,14 @@ var MemoryStore = function (name) {
};
/** Updates the value associated to a key in the store.
+ * @method MemoryStore#update
* @param {String} key - Key string.
* @param value - New value.
* @param {Function} success - Callback for a successful update operation.</param>
* @param {Function} [error] - Callback for handling errors. If not specified then store.defaultError is invoked.</param>
-
* This method errors out if the specified key is not found in the store.
*/
this.update = function (key, value, success, error) {
-
-
error = getErrorCallback(error);
if (validateKeyInput(key, error)) {
if (keys.hasOwnProperty(key)) {
@@ -209,9 +212,10 @@ var MemoryStore = function (name) {
}
}
};
-};
+}
/** Creates a store object that uses memory storage as its underlying mechanism.
+ * @method MemoryStore.create
* @param {String} name - Store name.
* @returns {Object} Store object.
*/
@@ -220,6 +224,7 @@ MemoryStore.create = function (name) {
};
/** Checks whether the underlying mechanism for this kind of store objects is supported by the browser.
+ * @method MemoryStore.isSupported
* @returns {Boolean} True if the mechanism is supported by the browser; otherwise false.
*/
MemoryStore.isSupported = function () {
@@ -237,4 +242,4 @@ MemoryStore.prototype.defaultError = throwErrorCallback;
*/
MemoryStore.prototype.mechanism = "memory";
-module.exports = MemoryStore;
+