Last active
May 3, 2016 13:27
-
-
Save mateusvahl/5de19d24488b440bb6beb4ce8435cc03 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
// Logged User can access they feed | |
var LoggedUser = { | |
neewsFeed: function() { | |
console.log('/feed'); | |
// return redirect('/feed') | |
} | |
} | |
// Let's represent the absence of an credential user | |
// https://en.wikipedia.org/wiki/Null_Object_pattern | |
var guestUser = { | |
neewsFeed: function() { | |
console.log('/login'); | |
// return redirect('/login'); | |
} | |
} | |
// Dispatch function based on user credentials | |
function userFactory(login, pass) { | |
if(login === 'user' && pass === 123) { | |
return LoggedUser; | |
} | |
return guestUser; | |
} | |
// This allow us to create generic methods! | |
// I don't want know if I have an logged user or not, | |
// just give-me an object to send messages | |
userFactory('user', 123).neewsFeed(); | |
userFactory('', '').neewsFeed(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment