0

I have come across this issues a few times now and I'd like to know if there is something I can do to mitigate the issue.

When using a waterfall dialog or dialog for that matter there are validators you can add to the dialog. These are associated in the class you are running the dialog against. Seemingly. But upon runtime the validator seems to be separate from class in which it is in.

Here is an example.

 this.addDialog(new TextPrompt(SOME_PROMPT, this.validateSomething))
     .addDialog(new TextPrompt(SOME_PROMPT2, this.validateOtherthing))

And say your class has a property

public mutableProperty1 = true;

and in the validator

private async validateSomething(context) Promise<any> {
    if (something happens here) {
       this.mutableProperty1 = false
       return true
    }
    return false
}

But that doesn't happen. When the retry prompt occurs the property is never mutated to the desired results. Why is this and is there anything I can do to get it mutated as intended?

Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66
Christian Matthew
  • 4,014
  • 4
  • 33
  • 43

1 Answers1

1

I believe this is more of a TypeScript/JavaScript question than a bot question. I suspect the problem is that the this keyword in the function does not refer to the object you think it does. Whenever you pass a function as a value without calling it, it's usually a good idea to bind the function to make sure this refers to the enclosing class instance.

this.addDialog(new TextPrompt(SOME_PROMPT, this.validateSomething.bind(this)))
    .addDialog(new TextPrompt(SOME_PROMPT2, this.validateOtherthing.bind(this)))
Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66
  • smh duh. lol thank you sir. sometimes when you use a framework so much you just think everything is in the box and forget the universe your're in. Also, you're right it's a code question but I think it is a good bot question because of how the functionality of its use is a good tool to know. – Christian Matthew May 14 '20 at 00:54
  • Hey Kyle, I tried to implement this today and I am getting a TS error `Property 'someProerty' does not exist on type 'typeof xxxxxxxxxxnitialDialog'.ts(2339)` even though the property is there and available in the class – Christian Matthew May 17 '20 at 05:53
  • Well I haven't seen your code, so it's no easier for me to troubleshoot that than it is for you. Are you declaring your properties or just initializing them? https://www.typescriptlang.org/docs/handbook/classes.html – Kyle Delaney May 18 '20 at 17:25