diff options
author | frankiebee <frankie.diamond@gmail.com> | 2017-04-22 05:00:32 +0800 |
---|---|---|
committer | frankiebee <frankie.diamond@gmail.com> | 2017-04-22 05:11:54 +0800 |
commit | 1b19b51e0823726a01eab49ef9416f852f365500 (patch) | |
tree | 1724b1fe557351bca0b4f3258b99a1533144322f | |
parent | 437c4acc9f6738ff5b07682860a72c270f2bfad6 (diff) | |
download | tangerine-wallet-browser-1b19b51e0823726a01eab49ef9416f852f365500.tar tangerine-wallet-browser-1b19b51e0823726a01eab49ef9416f852f365500.tar.gz tangerine-wallet-browser-1b19b51e0823726a01eab49ef9416f852f365500.tar.bz2 tangerine-wallet-browser-1b19b51e0823726a01eab49ef9416f852f365500.tar.lz tangerine-wallet-browser-1b19b51e0823726a01eab49ef9416f852f365500.tar.xz tangerine-wallet-browser-1b19b51e0823726a01eab49ef9416f852f365500.tar.zst tangerine-wallet-browser-1b19b51e0823726a01eab49ef9416f852f365500.zip |
Clean up code
-rw-r--r-- | mascara/src/lib/index-db-controller.js | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/mascara/src/lib/index-db-controller.js b/mascara/src/lib/index-db-controller.js index 1e4148b16..5aded1cbe 100644 --- a/mascara/src/lib/index-db-controller.js +++ b/mascara/src/lib/index-db-controller.js @@ -1,4 +1,3 @@ -// module.exports = const EventEmitter = require('events') module.exports = class IndexDbController extends EventEmitter { @@ -13,7 +12,7 @@ module.exports = class IndexDbController extends EventEmitter { } // Opens the database connection and returns a promise - open (version = this.version) { + open () { return this.get('dataStore') .then((data) => { if (!data) { @@ -42,10 +41,10 @@ module.exports = class IndexDbController extends EventEmitter { const self = this const dbOpenRequest = global.indexedDB.open(this.key, this.version) - dbOpenRequest.onupgradeneeded = (event) => { + dbOpenRequest.addEventListener('upgradeneeded', (event) => { this.db = event.target.result this.db.createObjectStore('dataStore') - } + }) dbOpenRequest.onsuccess = (event) => { this.db = dbOpenRequest.result @@ -53,20 +52,20 @@ module.exports = class IndexDbController extends EventEmitter { const dbTransaction = this.db.transaction('dataStore', 'readwrite') const request = dbTransaction.objectStore('dataStore') const objRequest = request[call](...args) - objRequest.onsuccess = (event) => { + objRequest.addEventListener('success', (event) => { return resolve(objRequest.result) - } - objRequest.onerror = (err) => { - return reject(err.message) - } - dbTransaction.oncomplete = (event) => { + }) + objRequest.addEventListener('error', (err) => { + return reject(`IndexDBController - ${call} failed to excute on indexedDB`) + }) + dbTransaction.addEventListener('complete', (event) => { this.emit('complete') - } + }) } - dbOpenRequest.onerror = (event) => { - return reject(event) - } + dbOpenRequest.addEventListener('error', (event) => { + return reject({message: `IndexDBController - open:@${call} failed to excute on indexedDB`, errorEvent: event}) + }) }) } } |