Created
May 22, 2023 19:31
-
-
Save mansha99/19455925f13d19adab77def553d72bde to your computer and use it in GitHub Desktop.
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 const fanSpeedInitial = { | |
level: 0, | |
status: 'OFF' | |
}; | |
export const ROTATE_RIGHT_ACTION = | |
{ type: 'ROTATE_RIGHT' }; | |
export const ROTATE_LEFT_ACTION = | |
{ type: 'ROTATE_LEFT' } | |
export function fanSpeedReducer(fanSpeed: any, action: any) { | |
if (action.type == 'ROTATE_RIGHT') { | |
if (fanSpeed.level == 0) { | |
return { level: 1, status: 'SLOW' }; | |
} | |
if (fanSpeed.level == 1) { | |
return { level: 2, status: 'MEDIUM' }; | |
} | |
if (fanSpeed.level == 2) { | |
return { level: 3, status: 'FAST' }; | |
} | |
return { level: 0, status: 'OFF' }; | |
} | |
if (action.type == 'ROTATE_LEFT') { | |
if (fanSpeed.level == 3) { | |
return { level: 2, status: 'MEDIUM' }; | |
} | |
if (fanSpeed.level == 2) { | |
return { level: 1, status: 'SLOW' }; | |
} | |
if (fanSpeed.level == 1) { | |
return { level: 0, status: 'OFF' }; | |
} | |
return { level: 3, status: 'FAST' }; | |
} | |
throw new Error(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment