Deferred tools comprise a couple of lightweight wrappers around common asynchronous APIs. These wrappers adapt the APIs to use jQuery's Deferred object rather than argument based callbacks.
Hey, its not much. But it can be helpful if you have already bought into using the jQuery Deferred object to handle asynchronous operations.
var db = window.openDatabaseDeferred('example', 1, 'Example Database', function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS Employee ( ID INTEGER PRIMARY KEY, Name VARCHAR )')
.done(function () {
console.log('Employee table created.');
});
});
db.transaction(function (tx) {
tx.executeSql('INSERT INTO Employee (ID, Name) VALUES (?, ?)', [1, 'John Smith']);
})
.done(function (result) {
console.log(result.rowsAffected + ' record(s) updated.');
})
.then(function (result) {
return db.transaction(function (tx) {
tx.executeSql('SELECT * FROM Employee WHERE ID = ?', [result.insertId]);
});
})
.then(function (result) {
console.log(results.rows.item(i).Name + ' was added as an employee.');
})
.fail(function () {
console.log('Something went wrong.');
})
window.openDatabaseDeferred( name, version, displayName, estimatedSize, creationCallback );
db.transaction( callback )
.done(function ( ) {})
.fail(function ( error ) {});
db.readTransaction( callback )
.done(function ( ) {})
.fail(function ( error ) {});
db.changeVersion( oldVersion, newVersion, callback )
.done(function ( ) {})
.fail(function ( error ) {});
transaction.executeSql( sqlStatement, sqlArguments, errorCallback )
.done(function ( transaction, resultSet ) {})
.fail(function ( transaction, error ) {});
Again, not much to see here beyond what you would expect. Fewer callbacks, more promises, if that is what you want.
window.requestFileSystemDeferred( type, size )
.done(function ( filesystem ) {})
.fail(function ( error ) {});
window.resolveLocalFileSystemURLDeferred( type, size )
.done(function ( entry ) {})
.fail(function ( error ) {});
fileEntry.getMetadata()
.done(function ( metadata ) {})
.fail(function ( error ) {});
fileEntry.moveTo( parent, newName )
.done(function ( entry ) {})
.fail(function ( error ) {});
fileEntry.copyTo( parent, newName )
.done(function ( entry ) {})
.fail(function ( error ) {});
fileEntry.remove()
.done(function () {})
.fail(function ( error ) {});
fileEntry.getParent()
.done(function ( entry ) {})
.fail(function ( error ) {});
fileEntry.createWriter()
.done(function ( fileWriter ) {})
.fail(function ( error ) {});
fileEntry.file()
.done(function ( file ) {})
.fail(function ( error ) {});
directoryEntry.getMetadata()
.done(function ( metadata ) {})
.fail(function ( error ) {});
directoryEntry.moveTo( parent, newName )
.done(function ( entry ) {})
.fail(function ( error ) {});
directoryEntry.copyTo( parent, newName )
.done(function ( entry ) {})
.fail(function ( error ) {});
directoryEntry.remove()
.done(function () {})
.fail(function ( error ) {});
directoryEntry.getParent()
.done(function ( entry ) {})
.fail(function ( error ) {});
directoryEntry.getFile( path, options )
.done(function ( entry ) {})
.fail(function ( error ) {});
directoryEntry.getDirectory( path, options )
.done(function ( entry ) {})
.fail(function ( error ) {});
directoryEntry.removeRecursively()
.done(function () {})
.fail(function ( error ) {});
directoryReader.readEntries()
.done(function ( entries ) {})
.fail(function ( error ) {});