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 Notification { | |
| constructor(service) { | |
| this.service = service; | |
| } | |
| notify(message) { | |
| this.service.send(message); | |
| } | |
| } |
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 DeliveryService { | |
| deliverOrder() { | |
| console.log("Delivering order..."); | |
| } | |
| } | |
| class PaymentService { | |
| processPayment() { | |
| console.log("Processing payment..."); | |
| } |
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 Notification { | |
| send(message) { | |
| console.log(`Sending notification: ${message}`); | |
| } | |
| } | |
| class EmailNotification extends Notification { | |
| send(message) { | |
| console.log(`Sending email: ${message}`); | |
| } |
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 Payment { | |
| constructor(strategy) { | |
| this.strategy = strategy; | |
| } | |
| pay(amount) { | |
| this.strategy.processPayment(amount); | |
| } | |
| } |
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 User { | |
| constructor(name) { | |
| this.name = name; | |
| } | |
| } | |
| class UserRepository { | |
| save(user) { | |
| console.log(`Saving ${user.name} to the database.`); | |
| } |
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
| import { useSelector, useDispatch } from "react-redux"; | |
| function MyReduxComponent() { | |
| const count = useSelector((state) => state.counter); | |
| const dispatch = useDispatch(); | |
| return ( | |
| <div> | |
| <p>Count: {count}</p> | |
| <button onClick={() => dispatch({ type: "INCREMENT" })}>Increment</button> |
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
| import React, { useEffect } from "react"; | |
| function MyComponent() { | |
| useEffect(() => { | |
| // Set up some side effect here, such as an event listener | |
| window.addEventListener("resize", handleResize); | |
| // Cleanup when the component unmounts | |
| return () => { | |
| window.removeEventListener("resize", handleResize); |
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
| import React, { useEffect, useState } from "react"; | |
| function MyComponent() { | |
| const [count, setCount] = useState(0); | |
| useEffect(() => { | |
| // This is similar to componentDidUpdate | |
| console.log(`Component updated, current count: ${count}`); | |
| // Conditionally trigger updates to avoid infinite loops |
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
| import React, { useEffect, useState } from "react"; | |
| function MyComponent() { | |
| const [data, setData] = useState(null); | |
| useEffect(() => { | |
| // This is similar to componentDidMount | |
| console.log("Component mounted"); | |
| // API call |
NewerOlder