Created
April 6, 2020 19:27
-
-
Save jucian0/c0cc14dfae3290e9b5287f513988fb34 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 Observable from "./Observer"; | |
const input = document.getElementById("text-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}`); | |
input.addEventListener("input", e => Observable.notify(e.target.value)); | |
firstSubscriberBtn.addEventListener("click", e => { | |
e.preventDefault(); | |
Observable.subscribe(firstText); | |
}); | |
secondSubscriberBtn.addEventListener("click", e => { | |
e.preventDefault(); | |
Observable.subscribe(secondtText); | |
}); | |
firstUnSubscriberBtn.addEventListener("click", e => { | |
e.preventDefault(); | |
Observable.unsubscribe(firstText); | |
}); | |
secondUnSubscriberBtn.addEventListener("click", e => { | |
e.preventDefault(); | |
Observable.unsubscribe(secondtText); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment