Observers & Observables

Zachary Schulz
2 min readNov 6, 2020

Whilst learning Angular, I started delving into Observables. The functionality to the observables seemed similar to another observer I’ve come to know and love through gaming… Minecraft observers. In this article, I will delve into the very basic understanding of these two topics and what similarities or differences they may have.

Minecraft Observer:

In Minecraft, an observer is a block who’s primary function is to send a pulse of Redstone in one direction when it “observes” or detects a change in state of the block in front of it. The pulse of Redstone allows to to connect to other block in Minecraft that accept a Redstone charge to activate and perform their various functions.

Angular Observable:

In Angular, an observable is a function that takes an observer object as it’s argument and returns cancellation logic of the observers. The observers of an observable are next, error, and complete. These handlers are callback methods defined to handle different notifications. Next handles the delivered values if the logic remains and moves unto different values. Error handles when the logic halts the execution of the observable due to an error. Complete handles when the logic halts the execution of the observable due to the logic ending its cycle/loop.

The Comparison:

The angular observer does not handle changes in state, rather it handles the values subscribed to via calling the subscribe method on the observable with the observer object as the argument. The Minecraft observer acts more like a function being called due to an event listener. That function being to initiate whatever “blocks” its Redstone is connected to. The event listener being a change in state of the block that it is observing.

The similarity between these two is the fact that they deal with a logical condition of an object and a return if conditions are met. Minecraft’s observer has two returns, Redstone being active or not, and Angular’s observable has three variable returns, where the returns can vary based off of the internal logic of the observers.

--

--