lodash-es#last TypeScript Examples

The following examples show how to use lodash-es#last. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: History.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
add(data) {
    if (isEqual(last(this.undos), data)) return;
    this.undos.push(data);
    // 因为undo的时候,会触发add.
    // 所以需要区分这个add是undo触发的,还是用户正常操作触发的。
    // 如果是用户正常操作触发的,需要清空redos
    if (!isEqual(this.curData, data)) {
      this.redos = [];
    }
    this.eventCenter.emit(EventType.HISTORY_CHANGE,
      {
        data: {
          undos: this.undos,
          redos: this.redos,
          undoAble: this.undos.length > 1,
          redoAble: this.redos.length > 0,
        },
      });
    if (this.undos.length > this.maxSize) {
      this.undos.shift();
    }
  }