Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function subscribe(listener) {
- if (typeof listener !== 'function') {
- throw new Error('Expected listener to be a function.')
- }
- let isSubscribed = true
- ensureCanMutateNextListeners()
- nextListeners.push(listener)
- return function unsubscribe() {
- if (!isSubscribed) {
- return
- }
- isSubscribed = false
- ensureCanMutateNextListeners()
- const index = nextListeners.indexOf(listener)
- nextListeners.splice(index, 1)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement