Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move some properties to prototypes.

  • Loading branch information...
commit 7c6fe9d9352beee3588ab5a455d7123b66c3c65e 1 parent 4deafa1
@nakamura-to authored
Showing with 172 additions and 147 deletions.
  1. +172 −147 lib/kagedb.js
View
319 lib/kagedb.js
@@ -252,15 +252,6 @@
methodName: target.kage_methodName,
additionalInfo: target.kage_additinalInfo
};
- },
-
- defineConstructorName: function defineConstructorName(instance) {
- if (instance && instance.constructor && typeof instance.constructor.name === "undefined") {
- var constructor = instance.constructor;
- Object.defineProperty(constructor, "name", {
- value: constructor.toString().match(/^function (\w*)/)[1]
- });
- }
}
};
@@ -290,10 +281,9 @@
throw new Error(event.kage_message);
};
this.onblocked = typeof settings.onblocked === "function" && settings.onblocked || function () {};
- helper.defineConstructorName(this);
}
- KageDB.version = "0.0.6";
+ KageDB.version = "0.0.7dev";
KageDB.indexedDB = indexedDB;
@@ -307,6 +297,10 @@
KageDB.KageCursor = KageCursor;
+ if (!KageDB.prototype.constructor.name) {
+ KageDB.prototype.constructor.name = "KageDB";
+ }
+
KageDB.prefix = function (message) {
return "[KageDB] " + message;
};
@@ -532,39 +526,45 @@
},
_kageDB: {
value: kageDB
- },
- name: {
- get: function () { return db.name; },
- enumerable: true
- },
- version: {
- get: function () {
- var version = parseInt(db.version || 0, 10);
- return isNaN(version) ? db.version : version;
- },
- enumerable: true
- },
- objectStoreNames: {
- get: function () { return db.objectStoreNames; },
- enumerable: true
- },
- onabort: {
- get: function () { return db.onabort;},
- set: function (value) { db.onabort = value; },
- enumerable: true
- },
- onerror: {
- get: function () { return db.onerror;},
- set: function (value) { db.onerror = value; },
- enumerable: true
- },
- onversionchange: {
- get: function () { return db.onversionchange;},
- set: function (value) { db.onversionchange = value; },
- enumerable: true
}
});
- helper.defineConstructorName(this);
+ }
+
+ KageDatabase.prototype = Object.create(Object.prototype, {
+ name: {
+ get: function () { return this._db.name; },
+ enumerable: true
+ },
+ version: {
+ get: function () {
+ var version = parseInt(this._db.version || 0, 10);
+ return isNaN(version) ? this._db.version : version;
+ },
+ enumerable: true
+ },
+ objectStoreNames: {
+ get: function () { return this._db.objectStoreNames; },
+ enumerable: true
+ },
+ onabort: {
+ get: function () { return this._db.onabort;},
+ set: function (value) { this._db.onabort = value; },
+ enumerable: true
+ },
+ onerror: {
+ get: function () { return this._db.onerror;},
+ set: function (value) { this._db.onerror = value; },
+ enumerable: true
+ },
+ onversionchange: {
+ get: function () { return this._db.onversionchange;},
+ set: function (value) { this._db.onversionchange = value; },
+ enumerable: true
+ }
+ });
+
+ if (!KageDatabase.prototype.constructor.name) {
+ KageDatabase.prototype.constructor.name = "KageDatabase";
}
KageDatabase.prototype.createObjectStore = function createObjectStore(name, optionalParameters) {
@@ -611,44 +611,51 @@
},
_kageDB: {
value: kageDB
- },
- mode: {
- get: function () {
- if (typeof tx.mode === "string") return tx.mode;
- switch (tx.mode) {
- case IDBTransaction.READ_ONLY: return "readonly";
- case IDBTransaction.READ_WRITE: return "readwrite";
- case IDBTransaction.VERSION_CHANGE: return "versionchange";
- default: return tx.mode;
- }
- },
- enumerable: true
- },
- db: {
- get: function () { return new KageDatabase(tx.db, kageDB); },
- enumerable: true
- },
- error: {
- get: function () { return tx.error; },
- enumerable: true
- },
- onabort: {
- get: function () { return tx.onabort;},
- set: function (value) { tx.onabort = value; },
- enumerable: true
- },
- onerror: {
- get: function () { return tx.onerror;},
- set: function (value) { tx.onerror = value; },
- enumerable: true
- },
- oncomplete: {
- get: function () { return tx.oncomplete;},
- set: function (value) { tx.oncomplete = value; },
- enumerable: true
}
});
- helper.defineConstructorName(this);
+ }
+
+ KageTransaction.prototype = Object.create(Object.prototype, {
+ mode: {
+ get: function () {
+ var tx = this._tx;
+ if (typeof tx.mode === "string") return tx.mode;
+ switch (tx.mode) {
+ case IDBTransaction.READ_ONLY: return "readonly";
+ case IDBTransaction.READ_WRITE: return "readwrite";
+ case IDBTransaction.VERSION_CHANGE: return "versionchange";
+ default: return tx.mode;
+ }
+ },
+ enumerable: true
+ },
+ db: {
+ get: function () { return new KageDatabase(this._tx.db, this._kageDB); },
+ enumerable: true
+ },
+ error: {
+ get: function () { return this._tx.error; },
+ enumerable: true
+ },
+ onabort: {
+ get: function () { return this._tx.onabort;},
+ set: function (value) { this._tx.onabort = value; },
+ enumerable: true
+ },
+ onerror: {
+ get: function () { return this._tx.onerror;},
+ set: function (value) { this._tx.onerror = value; },
+ enumerable: true
+ },
+ oncomplete: {
+ get: function () { return this._tx.oncomplete;},
+ set: function (value) { this._tx.oncomplete = value; },
+ enumerable: true
+ }
+ });
+
+ if (!KageTransaction.prototype.constructor.name) {
+ KageTransaction.prototype.constructor.name = "KageTransaction";
}
KageTransaction.prototype.objectStore =function objectStore(name) {
@@ -684,29 +691,35 @@
},
_kageDB: {
value: kageDB
- },
- name: {
- get: function() { return objectStore.name; },
- enumerable: true
- },
- keyPath: {
- get: function () { return objectStore.keyPath; },
- enumerable: true
- },
- indexNames: {
- get: function () { return objectStore.indexNames; },
- enumerable: true
- },
- transaction: {
- get: function () { return new KageTransaction(objectStore.transaction, kageDB); },
- enumerable: true
- },
- autoIncrement: {
- get: function () { return objectStore.autoIncrement; },
- enumerable: true
}
});
- helper.defineConstructorName(this);
+ }
+
+ KageObjectStore.prototype = Object.create(Object.prototype, {
+ name: {
+ get: function() { return this._objectStore.name; },
+ enumerable: true
+ },
+ keyPath: {
+ get: function () { return this._objectStore.keyPath; },
+ enumerable: true
+ },
+ indexNames: {
+ get: function () { return this._objectStore.indexNames; },
+ enumerable: true
+ },
+ transaction: {
+ get: function () { return new KageTransaction(this._objectStore.transaction, this._kageDB); },
+ enumerable: true
+ },
+ autoIncrement: {
+ get: function () { return this._objectStore.autoIncrement; },
+ enumerable: true
+ }
+ });
+
+ if (!KageObjectStore.prototype.constructor.name) {
+ KageObjectStore.prototype.constructor.name = "KageObjectStore";
}
KageObjectStore.prototype.put = function put(value, key, success, error) {
@@ -907,25 +920,31 @@
},
_kageDB: {
value: kageDB
- },
- name: {
- get: function () { return index.name; },
- enumerable: true
- },
- objectStore: {
- get: function () { return new KageObjectStore(index.objectStore, kageDB); },
- enumerable: true
- },
- keyPath: {
- get: function () { return index.keyPath; },
- enumerable: true
- },
- multiEntry: {
- get: function () { return index.multiEntry; },
- enumerable: true
}
});
- helper.defineConstructorName(this);
+ }
+
+ KageIndex.prototype = Object.create(Object.prototype, {
+ name: {
+ get: function () { return this._index.name; },
+ enumerable: true
+ },
+ objectStore: {
+ get: function () { return new KageObjectStore(this._index.objectStore, this._kageDB); },
+ enumerable: true
+ },
+ keyPath: {
+ get: function () { return this._index.keyPath; },
+ enumerable: true
+ },
+ multiEntry: {
+ get: function () { return this._index.multiEntry; },
+ enumerable: true
+ }
+ });
+
+ if (!KageIndex.prototype.constructor.name) {
+ KageIndex.prototype.constructor.name = "KageIndex";
}
KageIndex.prototype.openCursor = function openCursor(criteria, success, error) {
@@ -1015,39 +1034,45 @@
},
_kageDB: {
value: kageDB
- },
- source: {
- get: function () { return cursor.source; },
- enumerable: true
- },
- direction: {
- get: function () {
- var direction = cursor.direction;
- if (typeof direction === "string") return direction;
- switch (direction) {
- case IDBCursor.NEXT: return "next";
- case IDBCursor.NEXT_NO_DUPLICATE: return "nextunique";
- case IDBCursor.PREV: return "prev";
- case IDBCursor.PREV_NO_DUPLICATE: return "prevunique";
- default: return direction;
- }
- },
- enumerable: true
- },
- value: {
- get: function () { return cursor.value; },
- enumerable: true
- },
- key: {
- get: function () { return cursor.key; },
- enumerable: true
- },
- primaryKey: {
- get: function () { return cursor.primaryKey; },
- enumerable: true
}
});
- helper.defineConstructorName(this);
+ }
+
+ KageCursor.prototype = Object.create(Object.prototype, {
+ source: {
+ get: function () { return this._cursor.source; },
+ enumerable: true
+ },
+ direction: {
+ get: function () {
+ var direction = this._cursor.direction;
+ if (typeof direction === "string") return direction;
+ switch (direction) {
+ case IDBCursor.NEXT: return "next";
+ case IDBCursor.NEXT_NO_DUPLICATE: return "nextunique";
+ case IDBCursor.PREV: return "prev";
+ case IDBCursor.PREV_NO_DUPLICATE: return "prevunique";
+ default: return direction;
+ }
+ },
+ enumerable: true
+ },
+ value: {
+ get: function () { return this._cursor.value; },
+ enumerable: true
+ },
+ key: {
+ get: function () { return this._cursor.key; },
+ enumerable: true
+ },
+ primaryKey: {
+ get: function () { return this._cursor.primaryKey; },
+ enumerable: true
+ }
+ });
+
+ if (!KageCursor.prototype.constructor.name) {
+ KageCursor.prototype.constructor.name = "KageCursor";
}
KageCursor.prototype.update = function update(value, success, error) {
Please sign in to comment.
Something went wrong with that request. Please try again.