This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from 'preact/hooks'; | |
type StateSetter<T> = Partial<T> | ((currentState: T) => T); | |
export const createGlobalState = <T>(init: T) => { | |
const store = { | |
state: init, | |
get: (): Readonly<T> => store.state, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const csvToJson = (input) => { | |
const lines = input.split('\n'); | |
const keys = lines[0].split(','); | |
const dataset = lines.slice(1); | |
const res = []; | |
for (const data of dataset) { | |
console.log(data, keys); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Camera, Euler } from 'three'; | |
export class FirstPersonControls { | |
constructor(private camera: Camera, private domElement: HTMLElement) { | |
this.connect(); | |
} | |
state = { | |
mousedown: false, | |
enabled: false, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const combineLatestObj = <T>( | |
obj: T, | |
): Observable<{ [K in keyof T]: ObservedValueOf<T[K]> }> => { | |
const keys = Object.keys(obj); | |
const values = Object.values(obj); | |
return combineLatest(values).pipe( | |
map( | |
(observedValues) => | |
keys.reduce((result, key, i) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BehaviorSubject } from 'rxjs'; | |
import { distinctUntilChanged, map } from 'rxjs/operators'; | |
import produce from 'immer'; | |
type StateSetter<T> = Partial<T> | ((s: T) => T | void); | |
/** | |
* Simple abstraction to create an immutable like rxjs store. | |
*/ | |
export abstract class ObservableStore<T = unknown> { |