Last active
September 6, 2020 17:40
-
-
Save ashwinkumar2438/0fc11b7acc9a98dfd99afc6ff97c747e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//Global Scope. | |
var globaldata={user:"xyz",loggedin:false,currentstate:"none"} | |
var userinput="Current State Info"; | |
/* Impure way of handling login. Changing Global State, | |
operation is dependent upon global variable 'userinput', | |
no return value. | |
*/ | |
var login=(globaldata)=>{ | |
globaldata.loggedin=true; | |
globaldata.currentstate=userinput; | |
} | |
//Pure way of handling login. | |
var login=(globaldata,userinput)=>{ | |
var globaldatacopy={...globaldata}; | |
globaldatacopy.loggedin=true; | |
globaldatacopy.currentstate=userinput; | |
return globaldatacopy; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment