M
M
mortyy2017-03-26 16:31:47
Angular
mortyy, 2017-03-26 16:31:47

What is $timeout used for here?

I understand someone else's code and it is not clear why $timeout is used here?

_initThreadId() {
      const me = this;
      me.threadId = this.dialogs[0].threadId || me.dialogs[0].code;
      me.$timeout(function () {
        if (me._comeFromFooter()) me.threadId = _.find(me.dialogs, d => d.employeeType === me.employeeType).threadId;
        if (me._comeFromRepresentatives()) me.threadId = _.find(me.dialogs, d => d.employeeType === 'CLIENT_MANAGER').threadId;
      });
    }

    _comeFromRepresentatives() {
      return angular.isDefined(this.currentUserRepresentative);
    }

    _comeFromFooter() {
      return angular.isDefined(this.employeeType);
    }

It is also not clear why only the _comeFromRepresentatives function works, but does not enter _comeFromFooter().

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim, 2017-03-26
@wanhelsing

Read why they use the setTimeout(function, 0) technique at all. And perhaps this will give you an answer why exactly in this case they use timeout

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question