延迟事件实现的方法

时间:2016-02-10 10:32:54

标签: javascript promise

是否有任何标准方法来实施延期事件?例如,

service.on('before-file-delete', function(event){
    //here I want to show non-blocking confirm to user, wait for his response
    //and then either call event.preventDefault() or not
})

我目前的实施非常基础:

service.on('before-file-delete', function(event, file){
   event.deferredResult = showConfirm().then(function(result) {
        if (result === 1) { event.preventDefault(); }
   });
})

内部服务的发射器:

var event = emit('before-file-delete', file);
event.deferredResult.then(function () { 
      if (!event.defaultPrevented) {
      // file is not deleted until deferredResult is resolved
      file.delete();
}});

但我想知道是否有任何标准实施?

0 个答案:

没有答案