1
我想知道什么是链接延迟最好的设计。请考虑下面的代码片段:等待链接推迟完成
组件X:
_functionRaisingEvent: function()
{
$.when(this.raiseEvent('myEvent', args)).done(function(args){ // Check for args.cancel });
},
_raiseEvent: function(event, args)
{
var def = new $.Deferred();
// Call subscribers of myEvent in different components and pass them args
// Subscribers possibly make ajax calls
return def.promise();
},
认购Y:
_onMyEvent:function(args)
{
$.ajax(....).done(function(data){ if(data == 1) args.cancel = true;});
},
用户Z:
_onMyEvent:function(args)
{
document.getElementById('abx').display = 'block';
}
_functionRaisingEvent调用_raiseEvent这触发了用户的回调。
我想实现的是,在_functionRaisingEvent中完成的回调只在所有订户完成后才执行。
我应该通过订户自己的延期为参数和使用管道?任何最佳实践或设计模式?