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
| player1: { | |
| userName: 'sag1v', | |
| score: 700, | |
| __proto__: playerFunctions | |
| } | |
| player2: { | |
| userName: 'sarah', | |
| score: 900, | |
| __proto__: playerFunctions |
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
| { | |
| userName: 'sag1v', | |
| score: '700' | |
| } |
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
| class Player { | |
| constructor(userName, score) { | |
| this.userName = userName; | |
| this.score = score; | |
| } | |
| setScore(newScore) { | |
| this.score = newScore; | |
| } | |
| } |
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
| class Player { | |
| constructor(userName, score) { | |
| this.userName = userName; | |
| this.score = score; | |
| } | |
| setScore(newScore) { | |
| this.score = newScore; | |
| } | |
| } |
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
| const player1 = { | |
| userName: 'sag1v', | |
| score: '700', | |
| setScore(newScore){ | |
| player1.score = newScore; | |
| } | |
| } |
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
| const player1 = { | |
| name: 'Sagiv', | |
| } | |
| player1.userName = 'sag1v'; | |
| player1['score'] = 700; | |
| player1.setScore = function(newScore) { | |
| player1.score = newScore; | |
| } |
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
| class Player { | |
| } |
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
| useEffect(() => { | |
| if (pets.selectedPet) { | |
| dispatch({ type: "FETCH_PET" }); | |
| getPet(pets.selectedPet).then(data => { | |
| dispatch({ type: "FETCH_PET_SUCCESS", payload: data }); | |
| }); | |
| } else { | |
| dispatch({ type: "RESET" }); | |
| } | |
| }, [pets.selectedPet]); |
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
| export function getPet(type) { | |
| const delay = type === "cats" ? 3500 : 500; | |
| return new Promise(resolve => { | |
| // immulate fetch call | |
| setTimeout(() => { | |
| resolve(petsDB[type]); | |
| }, delay); | |
| }); | |
| } |
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
| function Pets() { | |
| const [pets, dispatch] = useReducer(petsReducer, initialState); | |
| const onChange = ({ target }) => { | |
| dispatch({ type: "PET_SELECTED", payload: target.value }); | |
| }; | |
| useEffect(() => { | |
| if (pets.selectedPet) { | |
| dispatch({ type: "FETCH_PET" }); |