addToStack(prevStack, simulateChat, shouldResetState) {
    const messagesOnStack = prevStack.slice(0);
    let { messages } = this.state;
    const nextMessage = messagesOnStack.splice(0, 1)[0];
    if (shouldResetState) {
      messages = [];
    }
    messages.push(nextMessage);
    this.setState({ messages });
    // if @param messagesOnStack is still a non-empty Array, addToStack(messagesOnStack).
    if (messagesOnStack.length > 0) {
      this._mainTimeout = setTimeout(() => {
        this.addToStack(messagesOnStack, simulateChat, false);
      }, simulateChat ? messagesOnStack[0].delay : 0);
    }
  }
/**
   * Given the previous stack (array of messages), takes 1 from array, pushes it to the conversation thread.
   * If the Array is still not empty, calls addToStack() again with the new Array, after a delay.
   * @param {Array} prevStack
   * @param {boolean} simulateChat
   * @param {boolean} shouldResetState
   */
Given the previous stack (array of messages), takes 1 from array, pushes it to the conversation thread.
If the Array is still not empty, calls addToStack() again with the new Array, after a delay.
Given the previous stack ( array of messages ) takes 1 from array pushes it to the conversation thread . If the Array is still not empty calls addToStack () again with the new Array after a delay .
addToStack(prevStack, simulateChat, shouldResetState) {
    const messagesOnStack = prevStack.slice(0);
    let { messages } = this.state;
    const nextMessage = messagesOnStack.splice(0, 1)[0];
    if (shouldResetState) {
      messages = [];
    }
    messages.push(nextMessage);
    this.setState({ messages });
    if (messagesOnStack.length > 0) {
      this._mainTimeout = setTimeout(() => {
        this.addToStack(messagesOnStack, simulateChat, false);
      }, simulateChat ? messagesOnStack[0].delay : 0);
    }
  }
addToStack ( prevStack , simulateChat , shouldResetState ) { const messagesOnStack = prevStack . slice ( 0 ) ; let { messages } = this . state ; const nextMessage = messagesOnStack . splice ( 0 , 1 ) [ 0 ] ; if ( shouldResetState ) { messages = [ ] ; } messages . push ( nextMessage ) ; this . setState ( { messages } ) ; if ( messagesOnStack . length > 0 ) { this . _mainTimeout = setTimeout ( ( ) => { this . addToStack ( messagesOnStack , simulateChat , false ) ; } , simulateChat ? messagesOnStack [ 0 ] . delay : 0 ) ; } }
Given the previous stack (array of messages), takes 1 from array, pushes it to the conversation thread.
Given the previous stack ( array of messages ) takes 1 from array pushes it to the conversation thread .
// if @param messagesOnStack is still a non-empty Array, addToStack(messagesOnStack).