Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. //Handles the local storage in the UI
  2. class Storage {
  3. static getPlayers() {
  4. let players;
  5. if (localStorage.getItem('players') === null) {
  6. players = [];
  7. } else {
  8. players = JSON.parse(localStorage.getItem('players'));
  9. }
  10.  
  11. return players;
  12. }
  13.  
  14. static addSoccerPlayer(player) {
  15. const players = Storage.getPlayers();
  16. players.push(player);
  17. localStorage.setItem('players', JSON.stringify(players));
  18. }
  19.  
  20. static removeSoccerPlayer(jerseynumber) {
  21. const players = Storage.getPlayers();
  22.  
  23. players.forEach((player, index) => {
  24. if (player.jerseynumber === jerseynumber) {
  25. players.splice(index, 1);
  26. }
  27. });
  28.  
  29. localStorage.setItem('players', JSON.stringify(players));
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement