This file contains 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
/* eslint-disable */ | |
// https://github.com/Chronstruct/display-primitives/issues/1#issuecomment-1518496207 | |
// declare global { | |
// namespace JSX { | |
// interface IntrinsicElements<T extends string> { | |
// input: React.DetailedHTMLProps< | |
// React.InputHTMLAttributes<HTMLInputElement>, | |
// HTMLInputElement |
This file contains 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 { | |
type AsyncAction, | |
action, | |
atom, | |
spawn, | |
take, | |
toAbortError, | |
isCausedBy, | |
} from '@reatom/framework'; | |
import { reatomComponent } from '@reatom/npm-react'; |
This file contains 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
// in the app root | |
const ROUTES = reatomRoutes({ | |
auth: { | |
login: {}, | |
registration: {}, | |
}, | |
goods: { | |
':id': { | |
edit: {}, | |
}, |
This file contains 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 { fingerprint } from 'src/infrastructure/fingerprint'; | |
import { Client, fetchExchange, makeOperation, mapExchange } from 'urql'; | |
export const client = new Client({ | |
url: '/api/graphql', | |
requestPolicy: 'network-only', | |
exchanges: [ | |
mapExchange({ | |
async onOperation(operation) { | |
return makeOperation(operation.kind, operation, { |
This file contains 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 { | |
type Atom, | |
type Action, | |
type Ctx, | |
type Rec, | |
atom, | |
action, | |
type Fn, | |
type CtxSpy, | |
isCausedBy, |
This file contains 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
export type UrlSearchParamsInit = ConstructorParameters< | |
typeof URLSearchParams | |
>[0]; | |
export interface FetchRequestInit< | |
Result = unknown, | |
Params = unknown, | |
Body = unknown | |
> extends RequestInit { | |
url?: string | URL; |
This file contains 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
// https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback | |
// https://github.com/reactjs/rfcs/pull/220#issuecomment-1259938816 | |
import React from 'react'; | |
// Allow to access a fresh closures in the function but returns stable reference during rerenders | |
export function useCallbackRef<T extends (...args: unknown[]) => unknown>(callback: T): T { | |
const ref: React.MutableRefObject<{ | |
stableFn: T; | |
callback: T; |
This file contains 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
// BASE | |
// debounce | |
const onChange = debounce((ctx, event) => { | |
inputAtom(ctx, event.currentTarget.value); | |
}, 500); | |
// concurrent | |
const onChange = concurrent(async (ctx, event) => { | |
await ctx.schedule(() => sleep(500)); |
This file contains 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 { AsyncAction } from '@reatom/async' | |
import { Atom, atom } from '@reatom/core' | |
export const withReadyAtom = | |
<T extends AsyncAction & { dataAtom?: Atom }>(initState = false) => | |
(anAsync: T): T & { readyAtom: Atom<boolean> } => { | |
// use `spy` to prevent any race conditions | |
const readyAtom = atom((ctx, state?: boolean) => { | |
// trigger connection to start the fetch if `onConnect` used | |
if (anAsync.dataAtom) ctx.spy(anAsync.dataAtom) |
This file contains 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
// create | |
export const { useAuth } = createContexts({ | |
Auth() { | |
const [a, setA] = React.useState("a"); | |
const [b, setB] = React.useState("b"); | |
return { | |
a, | |
b, | |
setA, |
NewerOlder