init function handler for custom button unable to set class variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bandtank
    Active Community Member
    • Mar 2017
    • 396

    #1

    init function handler for custom button unable to set class variable

    I added two buttons to an entity, each of which is meant to run a different action. This is what I am using to test the connectivity:

    Code:
    define(['action-handler'], (Dep) => {
      return class extends Dep {
    
        actionToRun = null
    
        initAdjust() {
          this.actionToRun = "adjust"
          console.log("adjust", this.actionToRun)
        }
    
        initSetPaid() {
          this.actionToRun = "setPaid"
          console.log("setPaid", this.actionToRun)
        }
    
        async runAction() {
          console.log("run action", this.actionToRun)
          return
        }
      }
    }
    When the page loads, this is what is printed to the console:
    Code:
    setPaid setPaid
    adjust adjust
    That makes sense and is what I expected to see. However, clicking either button results in the following output in the console:
    Code:
    run action null
    I don't understand the point of the init functions if the classes are unable to store state. What am I doing wrong?
Working...