-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Found what appears to be a good working implementation on NPM. Closes #15.
- Loading branch information
1 parent
ced419b
commit 54078ff
Showing
5 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { DBOpenDBRequest } = require('./request') | ||
|
||
function createEvent(type, bubbles, cancelable, detail) { | ||
return { | ||
type, | ||
timeStamp: Date.now(), | ||
bubbles: bubbles, | ||
cancelable: cancelable, | ||
detail: detail || null, | ||
} | ||
} | ||
|
||
class DBFactory { | ||
constructor (path) { | ||
console.log(path) | ||
} | ||
|
||
open (name, version = 0) { | ||
const request = new DBOpenDBRequest() | ||
setImmediate(() => { | ||
request.dispatchEvent(createEvent('upgradeneeded', false, false)) | ||
request.dispatchEvent(createEvent('success', false, false)) | ||
}) | ||
return request | ||
} | ||
} | ||
|
||
exports.DBFactory = DBFactory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
module.exports = 1 | ||
const path = require('path') | ||
|
||
const { DBFactory } = require('./factory') | ||
|
||
exports.indexedDB = new DBFactory(path.resolve(__dirname, './test/tmp/indexeddb')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
}, | ||
"dependencies": | ||
{ | ||
"event-target-shim": "5.0.1" | ||
}, | ||
"devDependencies": | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { EventTarget, defineEventAttribute } = require('event-target-shim') | ||
|
||
class DBRequest extends EventTarget { | ||
constructor () { | ||
super() | ||
this.source = null | ||
this.transaction = null | ||
this.readyState = 'pending' | ||
this.onsuccess = null | ||
this.onerror = null | ||
} | ||
} | ||
|
||
defineEventAttribute(DBRequest.prototype, 'error') | ||
defineEventAttribute(DBRequest.prototype, 'success') | ||
|
||
class DBOpenDBRequest extends DBRequest { | ||
constructor () { | ||
super() | ||
} | ||
} | ||
|
||
defineEventAttribute(DBOpenDBRequest.prototype, 'blocked') | ||
defineEventAttribute(DBOpenDBRequest.prototype, 'upgradeneeded') | ||
|
||
exports.DBRequest = DBRequest | ||
exports.DBOpenDBRequest = DBOpenDBRequest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
require('proof')(1, prove) | ||
require('proof')(1, (okay, callback) => { | ||
const { indexedDB } = require('..') | ||
okay(indexedDB, 'required') | ||
const request = indexedDB.open('test', 3) | ||
request.onupgradeneeded = function () { | ||
console.log('upgrading') | ||
return | ||
const db = request.result | ||
const store = db.createObjectStore('books', { keyPath: 'isbn' }) | ||
store.createIndex('by_title', 'title', { unique: true }) | ||
|
||
function prove (ok) { | ||
ok(require('..'), 'require') | ||
} | ||
store.put({ title: 'Quarry Memories', author: 'Fred', isbn: 123456 }) | ||
store.put({ title: 'Water Buffaloes', author: 'Fred', isbn: 234567 }) | ||
store.put({ title: 'Bedrock Nights', author: 'Barney', isbn: 345678 }) | ||
} | ||
request.onsuccess = function () { | ||
console.log('succeeded') | ||
} | ||
callback() | ||
}) |