Skip to content

Instantly share code, notes, and snippets.

@artalar
artalar / example.ts
Created May 28, 2024 21:43
reatomForm
import { atom, reatomAsync, withStatusesAtom } from '@reatom/framework';
import {
FunnelMinorFileType,
FileType,
type FunnelMinorFile as AssetFile,
type UpdateFunnelDataInput,
} from 'src/__generated__/graphql';
import { t } from 'src/admin/i18n';
import { type FormFieldOptions, reatomForm } from 'src/reatom-form';
import { reatomObjectUrl } from 'src/shared/reatomObjectUrl';
export const listResource = reatomResource(
(ctx) => request("api/list", ctx.controller),
"listResource"
).pipe(withCache(), withDataAtom([]));
export const updateList = reatomAction(async () => {
/* */
}, "updateList").pipe(withVariables());
export const List = reatomComponent(({ ctx }) => (
@artalar
artalar / cloc.txt
Last active May 16, 2024 07:29
GPT-4o inspects react compiler
npx cloc compiler
3668 text files.
2905 unique files.
767 files ignored.
github.com/AlDanial/cloc v 2.00 T=1.10 s (2642.9 files/s, 139378.2 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
/* 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
import {
type AsyncAction,
action,
atom,
spawn,
take,
toAbortError,
isCausedBy,
} from '@reatom/framework';
import { reatomComponent } from '@reatom/npm-react';
@artalar
artalar / example.tsx
Last active September 4, 2024 18:24
reatom-router
// in the app root
export const ROUTES = reatomRoutes({
auth: {
login: {},
registration: {},
},
goods: {
':id': {
edit: {},
},
@artalar
artalar / reatomList.ts
Last active March 19, 2024 05:13
reatomZod
import {
type Atom,
type Action,
type Ctx,
type Rec,
atom,
action,
type Fn,
type CtxSpy,
isCausedBy,
@artalar
artalar / index.ts
Created January 29, 2024 14:06
reatomFetch
export type UrlSearchParamsInit = ConstructorParameters<
typeof URLSearchParams
>[0];
export interface FetchRequestInit<
Result = unknown,
Params = unknown,
Body = unknown
> extends RequestInit {
url?: string | URL;
@artalar
artalar / client.ts
Last active April 28, 2024 00:28
reatomGql real example
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, {
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)