Skip to content

Instantly share code, notes, and snippets.

View arackaf's full-sized avatar
🏠
Working from home

Adam Rackis arackaf

🏠
Working from home
View GitHub Profile
@arackaf
arackaf / gist:896be89aeb4fd5e2deeebb02d52d3016
Created November 18, 2022 05:14
ts-component-wrapper.ts
// This should be declared as
// export function withActiveIndicator<T>(Component: FunctionComponent<T>): FunctionComponent<T>
// but styled components makes this extremely hard. For now, this approached brute forces the correct return type,
// so the result will be properly typed for the consumer, at the expense of some casts inside the function
export function withActiveIndicator<T>(Component: T): T {
const Wrapper = styled(Component as any)`
outline: 0;
&:focus > :first-child {
display: block;
}
var app = (function () {
'use strict';
function noop() { }
function assign(tar, src) {
// @ts-ignore
for (const k in src)
tar[k] = src[k];
return tar;
}
var app = (function () {
"use strict";
function t() {}
function n(t) {
return t();
}
function e() {
return Object.create(null);
}
function r(t) {
/*
Context is this brief twitter convo https://twitter.com/ryanflorence/status/1255655063021776897
It would seem like Remix would need a way to allow developers to sync their SSR'd initial data into a client-side
GraphQL cache, like Apollo, if they're using one.
For example, if you have
*/
const useSuspenseQuery = options => {
const [resource] = useState(() => new DataQueryingThingWithState());
resource.readLatest(options); //will throw a promise if not ready
useEffect(() => {
return () => resource.current.dispose(); //never call in the side rendering / "parallel universe" tree :(
}, []);
return resource.current.state; // or whatever
Stats accumulated from browser startup to previous page load; reload to get stats as of this page load.
Refresh
Histogram: ServiceWorkerCache.Cache.Keys2.IgnoreSearchDisabled recorded 7 samples, mean = 22.7 (flags = 0x41)
0 ------------------O (1 = 14.3%)
1 O (0 = 0.0%) {14.3%}
2 ------------------------------------------------------------------------O (4 = 57.1%) {14.3%}
3 ...
20 -----O (1 = 14.3%) {71.4%}
24 ...
export type BasicQuery<T extends keyof Query> = Pick<Query, T>;
export type AliasQuery<T extends Record<string, keyof Query>> = { [k in keyof T]: Query[T[k]] };
export type CombinedQuery<T extends keyof Query, U extends Record<string, keyof Query>> = BasicQuery<T> & AliasQuery<U>;
const justTesting1 = useQuery<BasicQuery<"allBooks" | "allSubjects">>(null);
const { data: data1 } = justTesting1;
data1.allSubjects;
const justTesting2 = useQuery<AliasQuery<{ sub: "allSubjects"; sub2: "allSubjects" }>>(null);
const { data: data2 } = justTesting2;
function readBooks(variableString) {
let variables = JSON.parse(variableString);
let { page = 1, pageSize = 50, title_contains, sort } = variables;
let predicate = null;
let limit = pageSize;
let skipAmount = (page - 1) * pageSize;
let skip, cursorSkip;
if (title_contains) {
function deleteItem(_id, table) {
let open = indexedDB.open("books", 1);
return new Promise(res => {
open.onsuccess = evt => {
let db = open.result;
let tran = db.transaction(table, "readwrite");
let objStore = tran.objectStore(table);
objStore.delete(_id).onsuccess = res;
};
function syncItem(item, table, transform = item => item) {
let open = indexedDB.open("books", 1);
return new Promise(res => {
open.onsuccess = evt => {
let db = open.result;
let tran = db.transaction(table, "readwrite");
let objStore = tran.objectStore(table);
objStore.get(item._id).onsuccess = ({ target: { result: itemToUpdate } }) => {
if (!itemToUpdate) {