-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
25 lines (20 loc) · 614 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import './style.css'
import pubsub from "./pubsub";
const btn = document.querySelector('button')
const publisher = {
publishEvent(){
const data = {msg: "TOP SECRET DATA"}
pubsub.publish('anEvent', data.msg)
}
}
const subscriber1 = pubsub.subscribe("anEvent", data => {
console.log(`"anEvent", was published with this data: ${data}`)
})
const subscriber2 = pubsub.subscribe("anEvent", data => {
console.log(`"anEvent", I am second subscriber2`)
})
btn.addEventListener('click', () => {
publisher.publishEvent();
subscriber1.unsubscribe()
subscriber2.unsubscribe()
})