Created
August 11, 2020 21:55
-
-
Save jucian0/7fbf0f03e3a3f28d6287f21e0c895d50 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
import "./styles.css"; | |
import PubSub from "./PubSub"; | |
const firstInput = document.getElementById("first-input"); | |
const secondInput = document.getElementById("second-input"); | |
const firstSubscriberBtn = document.getElementById("first-subscriber-btn"); | |
const secondSubscriberBtn = document.getElementById("second-subscriber-btn"); | |
const firstUnSubscriberBtn = document.getElementById("first-un-subscriber-btn"); | |
const secondUnSubscriberBtn = document.getElementById( | |
"second-un-subscriber-btn" | |
); | |
const textFirstSubscriber = document.getElementById("first-subscriber"); | |
const textSecondSubscriber = document.getElementById("second-subscriber"); | |
const firstText = (e) => (textFirstSubscriber.innerText = `${e}`); | |
const secondtText = (e) => (textSecondSubscriber.innerText = `${e}`); | |
firstInput.addEventListener("input", (e) => | |
PubSub.publish("first-event", e.target.value) | |
); | |
secondInput.addEventListener("input", (e) => | |
PubSub.publish("second-event", e.target.value) | |
); | |
firstSubscriberBtn.addEventListener("click", (e) => { | |
e.preventDefault(); | |
PubSub.subscribe("first-event", firstText); | |
}); | |
firstUnSubscriberBtn.addEventListener("click", (e) => { | |
e.preventDefault(); | |
PubSub.unsubscribe("first-event", firstText); | |
}); | |
secondSubscriberBtn.addEventListener("click", (e) => { | |
e.preventDefault(); | |
PubSub.subscribe("second-event", secondtText); | |
}); | |
secondUnSubscriberBtn.addEventListener("click", (e) => { | |
e.preventDefault(); | |
PubSub.unsubscribe("second-event", secondtText); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment