vue-draggle源码中的策略模式和柯里化

 const optionsAdded = {};
eventsListened.forEach(elt => {
      optionsAdded["on" + elt] = delegateAndEmit.call(this, elt);
    });
const eventsListened = ["Start", "Add", "Remove", "Update", "End"];
function delegateAndEmit(evtName) {
  return evtData => {
    if (this.realList !== null) {
      this["onDrag" + evtName](evtData);
    }
    emit.call(this, evtName, evtData);
  };
}

 

function emit(evtName, evtData) {
  this.$nextTick(() => this.$emit(evtName.toLowerCase(), evtData));
}

 

2.另一个方法的策略

 const optionsAdded = {};
 eventsToEmit.forEach(elt => {
      optionsAdded["on" + elt] = emit.bind(this, elt);
    });
const eventsToEmit = ["Choose", "Unchoose", "Sort", "Filter", "Clone"];
function emit(evtName, evtData) {
  this.$nextTick(() => this.$emit(evtName.toLowerCase(), evtData));
}

 

posted @ 2020-06-13 22:25  TTtttt5  阅读(273)  评论(0编辑  收藏  举报