Skip to content

Instantly share code, notes, and snippets.

Using Observables for One time Operations

An Observable Problem

Observables are useful for situations where a continuous stream of data needs to be handled... continuously.

However they're annoying and the mental model doesn't make sense when it's a one time data read such as a normal REST API call.

In this kind of situation the idea of calling subscribe() on something which isn't an inherent subscription is a forcing a square into a circle hole kind of situation.

# NEW MACHINE SETUP
###########################################
# platform
###########################################
sudo apt update && sudo apt dist-upgrade
sudo apt install -y apt-transport-https
sudo apt-get install -y build-essential
###########################################
@joefazz
joefazz / usePageVisibility.js
Last active March 10, 2019 22:23
PageVisibilityHook
import React, { useEffect } from 'react';
function usePageVisibility(onVisible, onHidden) {
const visibilityChange = 'visibilitychange';
function onVisibilityChange() {
if (document.hidden) {
onHidden();
} else {
onVisible();