Hey all. I have a button where the label to be updated based on the value of another class property. However, I can’t seem to work out how to hook up the getters/setters and update notification so that the _connectionBtnText
updates when connectionStatus
changes…
Any suggestions on the best way to accomplish this?
import { Observable } from 'data/observable'
enum CONNECTION_STATUS {
DISCONNECTED,
CONNECTING,
CONNECTED
}
export class HelloWorldModel extends Observable {
private connectionStatus: CONNECTION_STATUS
private _connectBtnText: string
constructor() {
super()
this.connectionStatus = CONNECTION_STATUS.DISCONNECTED
}
// MARK: Getters and Setters
get connectBtnText(): string {
switch (this.connectionStatus) {
case CONNECTION_STATUS.DISCONNECTED:
this._connectBtnText = "Connect"
break
case CONNECTION_STATUS.CONNECTING:
this._connectBtnText = "Connecting"
break
case CONNECTION_STATUS.CONNECTED:
this._connectBtnText = "Connected"
break
default:
break
}
return this._connectBtnText
}
set connectBtnText(value: string) {
this._connectBtnText = value
this.notifyPropertyChange("connectBtnText", value)
}
// MARK: Public methods
public onConnectBtnTap() {
this.connectionStatus = CONNECTION_STATUS.CONNECTING // THIS IS WHERE THE BUTTON LABEL SHOULD UPDATE
// ...etc
}
}