Skip to content

Instantly share code, notes, and snippets.

View RWalkling's full-sized avatar

Raphael Walkling RWalkling

  • Berlin, Germany
View GitHub Profile
import { MapDeltaStream } from '../delta-streams/streams/map'
import { Point } from './Points'
import { mapValues } from 'lodash'
import { deltaNone, deltaUnknown } from '../delta-streams/deltas/collection'
import mapDeltaStream from '../delta-streams/mapDeltaStream'
export default (points: MapDeltaStream<Point>): MapDeltaStream<number> => {
const outSubject = mapDeltaStream<number>({})
points.stream.subscribe(({ data, delta }) => {
@RWalkling
RWalkling / equalByPaths.ts
Created February 21, 2020 06:44
rxjs utils
import { get } from 'lodash'
export interface EqualByProperties<TObject extends object> {
(): (object1: TObject, object2: TObject) => boolean
<TKey extends keyof TObject>(key: TKey): EqualByProperties<TObject>
<TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1]>(
...key: readonly [TKey1, TKey2]
): EqualByProperties<TObject>
<TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1], TKey3 extends keyof TObject[TKey1][TKey2]>(
...key: readonly [TKey1, TKey2, TKey3]
import { Observable, Subject } from 'rxjs'
import { distinctUntilChanged, map, withLatestFrom } from 'rxjs/operators'
import { apply, assocPath, path } from 'ramda'
type StreamLens<TObject, TOriginal> = <TKey extends keyof TObject | undefined = undefined>(
key?: TKey,
) => TKey extends keyof TObject
? StreamLens<TObject[TKey], TOriginal>
: {
readonly stream: Observable<TObject>
function useObserved<TObject>(observable: Observable<TObject>) {
const [state, setState] = useState<TObject>()
useEffect(() => {
const subscription = observable.subscribe(setState)
return () => subscription.unsubscribe()
}, [])
return state
}