Skip to content

QuizNot attempted

Observer in the wild

Which of these are the Observer pattern?

Select all that apply.

1–4 to choose, Enter to submit
Show answer & explanation

Correct answers:

  • addEventListener
  • A Redux store's subscribe
  • RxJS Observables / IntersectionObserver
  • Observer means a subject keeps a list of listeners and notifies them on change: DOM addEventListener, Redux store.subscribe, RxJS Observables and IntersectionObserver all do exactly that.
  • Not Array.prototype.map: it transforms an array once, synchronously
  • nothing subscribes or gets notified.
  • Remember to unsubscribe to avoid leaks.