0

I am working on a database manager for an app. At a certain point I want to save some data like this:

//call the saveBillEvent
DatabaseManager.saveBillEvent(model, callbackfunc);

//accepts billeventmodel object
DatabaseManager.prototype.saveBillEvent = function(billEventModel, callback){
     db.transaction(
        RekeningDelen.DatabaseManager.databaseInstance,
        RekeningDelen.DatabaseManager.saveBillEventSQL,
        function(error) {
            console.log(error);
            console.log('transaction failed billeventspersons table creation ');
        },
        function(transactionId, result) {
            console.log("transcation success billeventspersons, set firstappboot to false");
            store.setItem("firstAppBoot", "false");
        }
    );
}

The saveBillEvent contains a transaction which at a given moment calls the saveBillEventSQL.

DatabaseManager.prototype.saveBillEventSQL = function(billEventModel, callback) {
  //here i need the billEventModel to create the SQL
    db.executeSql(
        transactionId,
        getAllBillEventsSQL,
        null,
        function(transactiondId, results) {
           //here i want to call the callback
            console.log('billevent saved ' + results);

        },
        function(response) {
            alert('fail1');
            console.log("SELECT billEvent query failed " +  response);
        }
    );
}

This function contains the final callback, which should call the passed callback, for a certain query and also needs the billEventModel to create the query. Thus the billEventModel and the callback should be passed to this function, but that's not possible since the transaction triggers it at a specific moment.

So my question is how to deal with this A(with params)->B(has params, but cant pass through)->C(needs params) problem?

I hope you all can understand my question, if not add a comment.

Sjaak Rusma
  • 1,424
  • 3
  • 23
  • 36
  • i do not exactly get the issue. But, did you try storing the data in a global variable? ( so you need not pass the params). – vivek_nk Apr 11 '14 at 07:05
  • The problem is that the saveBillEventSQL cant be controlled. I can not pass the callback through were I eventually need the callback(and the model). I could store the needed callback in a window variable, but thats not really a nice solution in my opinion. – Sjaak Rusma Apr 11 '14 at 07:09
  • If you cannot pass the callback function, the only other way is storing it somewhere and calling it elsewhere you need. If not global (i.e. window object), create a separate namespace and add the callback function and params as property in that. – vivek_nk Apr 11 '14 at 07:18
  • Thanks for your comments, I already guessed so actually. Could you expand on a 'seperate namespace'? Do you mean something like create a new 'class' and use that as some kind of transfer object with temp data? – Sjaak Rusma Apr 11 '14 at 07:21
  • 1
    See the first answer in this - http://stackoverflow.com/questions/881515/javascript-namespace-declaration – vivek_nk Apr 11 '14 at 07:22

0 Answers0