Git Product home page Git Product logo

deferred-tools's Introduction

Deferred-tools

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.

Example

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.');
})

API

window.openDatabaseDeferred( name, version, displayName, estimatedSize, creationCallback );

SQL Database

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 ) {});

SQL Transaction

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.

API

window.requestFileSystemDeferred( type, size )
	.done(function ( filesystem ) {})
	.fail(function ( error ) {});
window.resolveLocalFileSystemURLDeferred( type, size )
	.done(function ( entry ) {})
	.fail(function ( error ) {});

File Entry

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 ) {});

Directory Entry

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 ) {});

Directory Reader

directoryReader.readEntries()
	.done(function ( entries ) {})
	.fail(function ( error ) {});

deferred-tools's People

Contributors

gconnolly avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.