Angular Docs: Rx Library | Operators
import { of } from 'rxjs';
import { filter, map } from 'rxjs/operators';
const squareOdd = of(1, 2, 3, 4, 5)
.pipe(
filter(n => n % 2 !== 0),
map(n => n * n)
Angular Docs: Rx Library | Operators
import { of } from 'rxjs';
import { filter, map } from 'rxjs/operators';
const squareOdd = of(1, 2, 3, 4, 5)
.pipe(
filter(n => n % 2 !== 0),
map(n => n * n)
https://v12.angular.io/guide/comparing-observables#cheat-sheet
OPERATION | OBSERVABLE | PROMISE |
---|---|---|
Creation | new Observable((observer) => { observer.next(123); }); |
new Promise((resolve, reject) => { resolve(123); }); |
Transform | obs.pipe(map((value) => value * 2)); |
promise.then((value) => value * 2); |
Subscribe | sub = obs.subscribe((value) => { console.log(value) }); |
promise.then((value) => { console.log(value); }); |
Unsubscribe | sub.unsubscribe(); |
Implied by promise resolution. |
From Reactive Patterns for RxJS with Angular Chapter 7: Transforming Streams
Operator | Use Case |
---|---|
concatMap |
If the order is important and you need to process operations in sequence while waiting for completion. |
mergeMap |
If the order is not important and you need to process operations in parallel to enhance performance. |
switchMap |
If you need to put a cancellation logic to release resources and take always the most recent information. |
exhaustMap |
To ignore new observables while the current one is still ongoing. |
// Andrew Burgess, YouTube | |
// https://www.youtube.com/watch?v=Yvhad4zdPqI | |
export class Deferred<T, E = unknown> { | |
promise: Promise<T>; | |
resolve: (value: T) => void = () => null; | |
reject: (reason?: E) => void = () => null; | |
constructor() { | |
this.promise = new Promise({resolve, reject} => { |
# Install pyenv, to manage Python versions | |
brew update | |
brew install pyenv | |
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc | |
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc | |
echo 'eval "$(pyenv init -)"' >> ~/.zshrc | |
# Install the supported version of Python, as defined in .python-version | |
pyenv install |
# A really insane command that dumps all of the text content of a directory into | |
# a single pathname-delimited text file. I use this to share my repo with claude, | |
# in lieu of a co-pilot. | |
# ⚠️ WARNING: You should definitely add repo.txt to your .gitignore !! | |
alias dump-repo=' | |
# 2>/dev/null suppresses error messages if not in a Git repo | |
git_root=$(git rev-parse --show-toplevel 2>/dev/null) | |
if [ -z "$git_root" ]; then | |
echo "Not in a git repository" |
import { json } from "@remix-run/node"; | |
import type { LoaderFunction } from "@remix-run/node"; | |
// For session-specific data | |
export const sessionLoader: LoaderFunction = async ({ request }) => { | |
const data = await fetchSessionData(); | |
return json(data, { | |
headers: { | |
"Cache-Control": "private, max-age=3600", // Cache for 1 hour for this user only |