分享
三行代码  ›  专栏  ›  技术社区  ›  Smokey Dawson

功能链不工作角度5

  •  1
  • Smokey Dawson  · 技术社区  · 1 年前

    抱歉,不是一个函数链,但我有这个代码

    ActivityService._hubConnection.on('Send', (activity: ActivityDto) => {
       this.activity = activity;
       if (activity.title === 'LOGIN') {
          this.showActivity(`${activity.user.firstName} ${activity.user.surname} logged in.`);
       } else if (activity.title === 'COMMENT') {
          this.showActivity(`${activity.user.firstName} ${activity.user.surname} commented on: XB-ID-${activity.messageId}`, `/app/main/dashboard/xpert-detail/${activity.messageId}/comment`, null);
       } else if (activity.title === 'ASSIGNED') {
          this.showActivity(`${activity.user.firstName} ${activity.user.surname} assigned: XB-ID-${activity.messageId}`, `/app/main/dashboard/xpert-detail/${activity.messageId}/comment`);
       } else if (activity.title === 'SYNC COMPLETE') {
          this.showActivity(`Sync complete, View Changes`, `/app/main/dashboard/alerts/all`, 'complete');
       } else if (activity.title === 'FILE') {
          this.showActivity(`${activity.user.firstName} ${activity.user.surname} filed: XB-ID-${activity.messageId}`, `/app/main/dashboard/xpert-detail/${activity.messageId}/comment`)
       } else if (activity.title === 'XPERT SYNC') {
          this.showActivity(`Sync In Progress.`, `/app/main/dashboard/activity`, 'start' );
       }
    });
    
     showActivity(popText, notifLink = null, sync = null) {
        this.popupText = popText;
        if (notifLink !== null) {
            this.notifLink = notifLink;
        }
        if (sync !== null) {
            if (sync === 'complete') {
                this._activityService.finishSync();
            } else if (sync === 'start') {
                this._activityService.startSync();
            }
        }
        this.showNotif();
    }
    
    showNotif() {
        const notif = <HTMLElement>document.querySelector('.notification-tab');
        notif.style.display = 'flex';
        notif.style.bottom = '0';
        setTimeout(() => {
            notif.style.bottom = '-50px';
            setTimeout(() => {
                notif.style.display = 'none';
            }, 500);
        }, 5000);
    }
    

    现在我不明白为什么这不起作用了,基本上发生的事情就是说我收到了一条评论,所以activity.title=='评论',它应该运行 showActivity() 函数,然后运行 showNotif() 函数,我在函数的每个部分放置断点,断点命中this.showActivity(),但什么也没有发生?其他断点都没有命中,我也不知道是什么问题!这对我来说毫无意义。

    任何帮助都会得到感激,我不知道会出什么问题…

    谢谢

    1 回复  |  直到 1 年前
        1
  •  2
  •   simpleDmitry    1 年前

      showActivity(popText, notifLink = null, sync = null) {
       try  {
        this.popupText = popText;
        if (notifLink !== null) {
          this.notifLink = notifLink;
        }
        if (sync !== null) {
          if (sync === 'complete') {
            this._activityService.finishSync();
          } else if (sync === 'start') {
            this._activityService.startSync();
          }
        }
        this.showNotif();
       } catch (e) {
        console.error(e);
       }
    }
    

    也在这里包装)

    if (activity.title === 'COMMENT') {
      try {
        this.showActivity(`${activity.user.firstName} ${activity.user.surname} commented on: XB-ID-${activity.messageId}`, `/app/main/dashboard/xpert-detail/${activity.messageId}/comment`, null);
      } catch (e) {
        console.error(e);
      }
    }