Created
November 18, 2011 00:57
-
-
Save buley/1375163 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
I'm working on an IndexedDB-only wrapper for just this purpose. If you don't mind that it's not yet released, there's not readme and my commits are fast-paced and not descriptive than maybe you should [check it out][1]. | |
There should be an example of every function in [indbapp.dev.js][2]. Here's how you would use the vanilla `InDBApp`: | |
I am in my third rewrite of a JavaScript application that heavily relies on IDB. I got sick of writing boilerplate IndexeDB code (setting up transactions, setting onsuccess callbacks, etc.) and decided to write a reusable interface. | |
That API is true to the IndexedDB spec and is now the core of InDB. It servers as a private object inside a wrapper that tries to simplify the interface. I'm writing my own [libraries][3] on top of it so I'm learning about what works and doesn't work and trying to improve InDB along the way. | |
[1]: https://github.com/editor/InDB | |
[2]: https://github.com/editor/InDB/blob/master/indbapp.dev.js | |
[3]: https://raw.github.com/editor/Neural/master/neural.dev.js | |
/* InDBApp to decorate */ | |
var Private | |
, Public = function ( request ) { | |
var current_database = "Yourapp"; | |
var current_description = "A basic InDB application." | |
if( 'undefined' !== typeof request ) { | |
if( 'undefined' !== typeof request.database ) { | |
current_database = request.database; | |
} | |
if( 'undefined' !== typeof request.description ) { | |
current_description = request.description; | |
} | |
} | |
Private = new InDBApp( { 'database': current_database, 'description': current_description } ); | |
}; | |
Public.prototype.get = function( request ) { | |
var req = new Object() | |
, type = request.type || {} | |
, on_success = request.on_success || null | |
, on_error = request.on_error || null | |
, on_complete = request.on_complete || null | |
, attr; | |
delete request.type; | |
delete request.on_success; | |
delete request.on_error; | |
delete request.on_complete; | |
for( attr in request ) { | |
req[ attr ] = request[ attr ]; | |
} | |
req.on_success = function( value ) { | |
if( true === debug ) { | |
console.log( 'Public.prototype.get success', value ); | |
} | |
if( 'function' == typeof on_success ) { | |
on_success( value ); | |
} | |
}; | |
req.on_error = function( context ) { | |
if( true === debug ) { | |
console.log( 'Public.prototype.get error', context ); | |
} | |
if( 'function' == typeof on_error ) { | |
on_error( context ); | |
} | |
}; | |
req.on_complete = function() { | |
if( true === debug ) { | |
console.log( 'Public.prototype.get complete' ); | |
} | |
if( 'function' == typeof on_complete ) { | |
on_complete(); | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment