Created
October 29, 2020 06:33
-
-
Save jcyh0120/64c1be1886b18c18a5b43a6c0925ac59 to your computer and use it in GitHub Desktop.
question: typescript for iot device?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface LEDStates1 { | |
LED1: "OFF" | "ON"; | |
} | |
export interface LEDStates2 { | |
LED1: "OFF" | "ON"; | |
LED2: "OFF" | "ON"; | |
LED3: "OFF" | "ON"; | |
} | |
type LED = "LED1" | "LED2" | "LED3" | |
export interface IState { | |
id: string; | |
online: "OFFLINE" | "ONLINE"; | |
mode: "Standby" | "Working"; | |
LEDStates: LEDStates1 | LEDStates2 | |
} | |
class LightBulb1 implements IState { | |
id: string = "123"; | |
online: "OFFLINE" | "ONLINE" = "OFFLINE" | |
mode: "Standby" | "Working" = "Working"; | |
LEDStates: LEDStates1 | |
constructor(states: IState) { | |
this.LEDStates = states.LEDStates | |
} | |
turnOn (led: LED) { | |
this.LEDStates[led] = "ON" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type LED = "LED1" | "LED2" | "LED3" | |
export interface LEDStates1 { | |
LED1: "OFF" | "ON"; | |
} | |
export interface LEDStates2 { | |
LED1: "OFF" | "ON"; | |
LED2: "OFF" | "ON"; | |
LED3: "OFF" | "ON"; | |
} | |
export interface IState1 { | |
id: string; | |
online: "OFFLINE" | "ONLINE"; | |
mode: "Standby" | "Working"; | |
LEDStates: LEDStates1 | |
} | |
export interface IState2 { | |
id: string; | |
online: "OFFLINE" | "ONLINE"; | |
mode: "Standby" | "Working"; | |
LEDStates: LEDStates2 | |
} | |
class LightBulb1 implements IState1 { | |
id: string = "123"; | |
online: "OFFLINE" | "ONLINE" = "OFFLINE" | |
mode: "Standby" | "Working" = "Working"; | |
LEDStates: LEDStates1 | |
constructor(states: IState1) { | |
this.LEDStates = states.LEDStates | |
} | |
turnOn (led: LED) { | |
this.LEDStates[led] = "ON" | |
} | |
} | |
class LightBulb implements IState2 { | |
id: string = "123"; | |
online: "OFFLINE" | "ONLINE" = "OFFLINE" | |
mode: "Standby" | "Working" = "Working"; | |
LEDStates: LEDStates2 | |
constructor(states: IState2) { | |
this.LEDStates = states.LEDStates | |
} | |
turnOn (led: LED) { | |
this.LEDStates[led] = "ON" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment