Class Index | File Index

Classes


Class baja.comm.Callback


Extends BaseBajaObj.
Network Callback.

A Callback object has ok and fail methods. It is used to make a comms call in BajaScript. When a comms call is made, additional callbacks may be needed to process the incoming data before calling the original ok or fail callbacks are executed. Therefore, extra help functions have been added to this object to for convenience.

This method should only be used internally by BajaScript. It should never appear in the public API.
Defined in: comm.js.

Class Summary
Constructor Attributes Constructor Name and Description
<private>  
Method Summary
Method Attributes Method Name and Description
<private>  
addFail(newFail)
Add a 'fail' callback.
<private>  
addOk(newOk)
Add an 'ok' callback.
<private>  
addReq(channel, key, body)
Add a request to the callback's batch object.
<private>  
If a Batch object was originally passed in when this object was created then commit the Batch.
<private>  
Commit the this object's Batch

This asynchronously makes a network call

<private>  
Synchronously commit this object's batch

Please note that baja.comm.Commit#commit should always be used in preference as this will result in a synchronous network call that will block everything else.

<private>  
Return this object's batch object
<private>  
Return true if the batch object was originally defined when the batch was created.
Methods borrowed from class BaseBajaObj:
equals, valueOf
Class Detail
<private> baja.comm.Callback()
Method Detail
<private> addFail(newFail)
Add a 'fail' callback.

When calling some BajaScript that causes a network call, there will be other callbacks that need to be processed before the original 'user' callbacks are invoked. Therefore, 'addOk' and 'addFail' can be used to chain up extra Callbacks if needed.

  // Create a callback object with user's original ok and fail function callbacks...
  var cb = new baja.comm.Callback(ok, fail, batch);

  // Add an intermediate callback...
  cb.addFail(function (ok, fail, err) {
    // Process the error messages before calling the original 'fail' callback...
    var niceMsg = processError(err);
    
    // Now call 'fail' callback passed in with processed error message...
    fail(niceMsg);
  });

Please note, that when adding an intermediate calllback, the 'ok' or 'fail' method passed in must be called at some point.

Parameters:
{Function} newFail
the callback Function. This function must accept three arguments including the current ok and fail function as well as any arguments specific to the callback function. By convention, the 'ok' or 'fail' functions passed in must be called after the new callback has finished.
See:
baja.comm.Callback#fail

<private> addOk(newOk)
Add an 'ok' callback.

When calling some BajaScript that causes a network call, there will be other callbacks that need to be processed before the original 'user' callbacks are invoked. Therefore, 'addOk' and 'addFail' can be used to chain up extra Callbacks if needed.

  // Create a callback object with user's original ok and fail function callbacks...
  var cb = new baja.comm.Callback(ok, fail, batch);

  // Add an intermediate callback...
  cb.addOk(function (ok, fail, resp) {
    // Process the response 'resp' object...
    var val = processResponse(resp);
    
    // Now call 'ok' callback passed in with processed response...
    ok(val);
  });

Please note, that when adding an intermediate calllback, the 'ok' or 'fail' method passed in must be called at some point.

This method is also extremely useful for intermediate callbacks that need to make other asynchronous network calls before calling the user's original 'ok' or 'fail' callback functions.

Parameters:
{Function} newOk
the callback Function. This function must accept three arguments including the current ok and fail function as well as any arguments specific to the callback function. By convention, the 'ok' or 'fail' functions passed in must be called after the new callback has finished.
See:
baja.comm.Callback#fail

<private> addReq(channel, key, body)
Add a request to the callback's batch object.
Parameters:
{String} channel
{String} key
body
See:
baja.comm.Batch#addReq

<private> autoCommit()
If a Batch object was originally passed in when this object was created then commit the Batch. Otherwise do nothing.

Therefore, if a Batch was originally passed into this Callback object, it is assumed the caller will invoke the Batch commit method when appropriate (i.e. they've batched up all of the network requests that are going to be made).

See:
baja.comm.Batch#commit
baja.comm.Callback#isOrgBatchDef

<private> commit()
Commit the this object's Batch

This asynchronously makes a network call

See:
baja.comm.Batch#commit

<private> commitSync()
Synchronously commit this object's batch

Please note that baja.comm.Commit#commit should always be used in preference as this will result in a synchronous network call that will block everything else.

See:
baja.comm.Callback#commit

<private> {baja.comm.Batch} getBatch()
Return this object's batch object
Returns:
{baja.comm.Batch}

<private> {Boolean} isOrgBatchDef()
Return true if the batch object was originally defined when the batch was created.
Returns:
{Boolean}

Documentation generated by JsDoc Toolkit 2.3.2