Skip to content

Instantly share code, notes, and snippets.

@ashwinkumar2438
Last active September 6, 2020 17:40
Show Gist options
  • Save ashwinkumar2438/0fc11b7acc9a98dfd99afc6ff97c747e to your computer and use it in GitHub Desktop.
Save ashwinkumar2438/0fc11b7acc9a98dfd99afc6ff97c747e to your computer and use it in GitHub Desktop.
//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