深入分析DWREngine.endBatch


DWREngine.endBatch将在DWREngine._execute最后被调用

--〉DWREngine._execute--〉DWREngine.endBatch)

 

/**

* Finished grouping a set of remote calls together. Go and execute them all.

* @see http://getahead.ltd.uk/dwr/browser/engine/batch

*/

 

//函数定义

DWREngine.endBatch = function(options) {

//设置请求对象

var batch = DWREngine._batch;

 

//请求对象为空返回

if (batch == null) {

DWREngine._handleError("No batch in progress.");

return;

}

// Merge the global batch level properties into the batch meta data

 

//如果形参存在那么有如下两步,通常行参是不存在的, 在DWREngine._execute中是如此调用endBatch的:DWREngine.endBatch();


 

if (options && options.preHook) batch.preHooks.unshift(options.preHook);

if (options && options.postHook) batch.postHooks.push(options.postHook);

 

//除非你写程序时调用过DWREngine.setPreHook,否则下面代码无用

if (DWREngine._preHook) batch.preHooks.unshift(DWREngine._preHook);

 

//除非你写程序时调用过DWREngine.setPostHook,否则下面代码无用

if (DWREngine._postHook) batch.postHooks.push(DWREngine._postHook);

 

//除非你手工改过源代码,否则下面的4个判断条件肯定为真

//DWREngine._method默认为1,表示采用XMLHttpRequest,除非你写程序时调用过DWREngine.setMethod

if (batch.method == null) batch.method = DWREngine._method;

//DWREngine._verb默认为"post",除非你写程序时调用过DWREngine.setVerb

if (batch.verb == null) batch.verb = DWREngine._verb;

//DWREngine._async默认为true,表示请求是异步的,除非你写程序时调用过DWREngine.setAsync

if (batch.async == null) batch.async = DWREngine._async;

//DWREngine.timeout 默认为0,除非你写程序时调用过DWREngine.setTimeout,

if (batch.timeout == null) batch.timeout = DWREngine._timeout;

 

//标记请求未完成

batch.completed = false;

 

// We are about to send so this batch should not be globally visible

//将DWREngine._batch赋值给临时变量batch后,将DWREngine._batch设为空

DWREngine._batch = null;

 

// If we are in ordered mode, then we don't send unless the list of sent

// items is empty

 

//判断DWREngine._ordered,默认为false

if (!DWREngine._ordered) {

DWREngine._sendData(batch);

//将请求对象放入请求数组,暂时没看出有什么用

DWREngine._batches[DWREngine._batches.length] = batch;

}

//如果通过调用DWREngine.setOrdered设置了_ordered,那么会使用_batchQueue,且进入下面的else块,否则不用理会下面的代码

else {

if (DWREngine._batches.length == 0) {

// We aren't waiting for anything, go now.

DWREngine._sendData(batch);

DWREngine._batches[DWREngine._batches.length] = batch;

}

else {

// Push the batch onto the waiting queue

DWREngine._batchQueue[DWREngine._batchQueue.length] = batch;

}

}

};

 

总结:

此函数主要是设置请求对象属性:_preHooks,postHooks,method,verb ,async ,timeout

然后调用DWREngine._sendData(batch);最后将请求加入数组或队列

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值