Skip to content

Instantly share code, notes, and snippets.

@jucian0
Created April 6, 2020 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jucian0/c0cc14dfae3290e9b5287f513988fb34 to your computer and use it in GitHub Desktop.
Save jucian0/c0cc14dfae3290e9b5287f513988fb34 to your computer and use it in GitHub Desktop.
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