Cleanup coffeescript for Android

This commit is contained in:
Chris Brody 2012-04-22 08:20:16 +02:00
parent d773caafd8
commit 2d8f867990

View File

@ -1,4 +1,6 @@
(-> do ->
root = @
SQLitePlugin = (dbPath, openSuccess, openError) -> SQLitePlugin = (dbPath, openSuccess, openError) ->
console.log "SQLitePlugin" console.log "SQLitePlugin"
@dbPath = dbPath @dbPath = dbPath
@ -13,26 +15,11 @@
) )
@open @openSuccess, @openError @open @openSuccess, @openError
return return
SQLitePluginTransaction = (dbPath) ->
console.log "root.SQLitePluginTransaction.SQLitePluginTransaction"
@dbPath = dbPath
@executes = []
@trans_id = get_unique_id()
@__completed = false
@__submitted = false
@optimization_no_nested_callbacks = true
console.log "root.SQLitePluginTransaction - this.trans_id:" + @trans_id
transaction_queue[@trans_id] = []
transaction_callback_queue[@trans_id] = new Object()
return
root = undefined
root = this
console.log "root.SQLitePlugin"
SQLitePlugin::openDBs = {} SQLitePlugin::openDBs = {}
SQLitePlugin::transaction = (fn, error, success) -> SQLitePlugin::transaction = (fn, error, success) ->
console.log "SQLitePlugin.prototype.transaction" t = new SQLitePluginTransaction(@dbPath)
t = undefined
t = new root.SQLitePluginTransaction(@dbPath)
fn t fn t
t.complete success, error t.complete success, error
@ -51,7 +38,6 @@
PhoneGap.exec null, null, "SQLitePlugin", "close", [ @dbPath ] PhoneGap.exec null, null, "SQLitePlugin", "close", [ @dbPath ]
root.SQLitePlugin = SQLitePlugin
get_unique_id = -> get_unique_id = ->
id = new Date().getTime() id = new Date().getTime()
id2 = new Date().getTime() id2 = new Date().getTime()
@ -59,8 +45,23 @@
id2 + "000" id2 + "000"
transaction_queue = [] transaction_queue = []
transaction_callback_queue = new Object() transaction_callback_queue = {}
console.log "root.SQLitePluginTransaction"
SQLitePluginTransaction = (dbPath) ->
@dbPath = dbPath
@executes = []
@trans_id = get_unique_id()
@__completed = false
@__submitted = false
# this.optimization_no_nested_callbacks: default is true.
# if set to true large batches of queries within a transaction will be much faster but
# you will lose the ability to do multi level nesting of executeSQL callbacks
@optimization_no_nested_callbacks = true
console.log "SQLitePluginTransaction - this.trans_id:" + @trans_id
transaction_queue[@trans_id] = []
transaction_callback_queue[@trans_id] = new Object()
return
SQLitePluginTransaction.queryCompleteCallback = (transId, queryId, result) -> SQLitePluginTransaction.queryCompleteCallback = (transId, queryId, result) ->
console.log "SQLitePluginTransaction.queryCompleteCallback" console.log "SQLitePluginTransaction.queryCompleteCallback"
query = null query = null
@ -182,12 +183,10 @@
transaction_callback_queue[@trans_id]["error"] = errorcb transaction_callback_queue[@trans_id]["error"] = errorcb
PhoneGap.exec null, null, "SQLitePlugin", "executeSqlBatch", transaction_queue[@trans_id] PhoneGap.exec null, null, "SQLitePlugin", "executeSqlBatch", transaction_queue[@trans_id]
# required for callbacks:
root.SQLitePluginTransaction = SQLitePluginTransaction root.SQLitePluginTransaction = SQLitePluginTransaction
root.sqlitePlugin = openDatabase: (dbPath, version, displayName, estimatedSize, creationCallback, errorCallback) ->
version = null unless version? root.sqlitePlugin =
displayName = null unless displayName? openDatabase: (dbPath, version, displayName, estimatedSize, creationCallback, errorCallback) ->
estimatedSize = 0 unless estimatedSize? new SQLitePlugin(dbPath, creationCallback, errorCallback)
creationCallback = null unless creationCallback?
errorCallback = null unless errorCallback?
new SQLitePlugin(dbPath, creationCallback, errorCallback)
).call this