-
-
Save Caballerog/5c7bcb341a622dd4cf78413bd3f41512 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
/** | |
* @class Controller | |
* | |
* Links the user input and the view output. | |
* | |
* @param model | |
* @param view | |
*/ | |
class UserController { | |
constructor(userService, userView) { | |
this.userService = userService; | |
this.userView = userView; | |
// Explicit this binding | |
this.userService.bindUserListChanged(this.onUserListChanged); | |
this.userView.bindAddUser(this.handleAddUser); | |
this.userView.bindEditUser(this.handleEditUser); | |
this.userView.bindDeleteUser(this.handleDeleteUser); | |
this.userView.bindToggleUser(this.handleToggleUser); | |
// Display initial users | |
this.onUserListChanged(this.userService.users); | |
} | |
onUserListChanged = users => { | |
this.userView.displayUsers(users); | |
}; | |
handleAddUser = user => { | |
this.userService.add(user); | |
}; | |
handleEditUser = (id, user) => { | |
this.userService.edit(id, user); | |
}; | |
handleDeleteUser = id => { | |
this.userService.delete(id); | |
}; | |
handleToggleUser = id => { | |
this.userService.toggle(id); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment