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 { createStore, createEvent, type Event, type Store } from "effector"; | |
import { useStoreMap, useEvent } from "effector-react/scope"; | |
import { useCallback } from "react"; | |
type Key = string; | |
type SetPayload<T> = { key: Key; value: T }; | |
type KeyValueStore<T> = Record<Key, T>; | |
type KV<T> = { | |
set: Event<SetPayload<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
type WithAutocomplete<T, U = string> = T | (U & Record<never, never>) | |
type ArrayItemType<T> = T extends (infer U)[] ? U : never | |
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>; | |
type TupleToObject< | |
T extends readonly any[], | |
M extends Record<Exclude<keyof T, keyof any[]>, PropertyKey>, | |
> = { [K in Exclude<keyof T, keyof any[]> as M[K]]: T[K] } |
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
const start = createEvent() | |
const waitFx = createEffect(ms => { | |
return new Promise(r => setTimeout(r, ms)) | |
}) | |
const $ = createStore(null) | |
sample({ | |
clock: start, | |
fn: () => 3_000, |
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
const isFirstServerCall = req?.url?.indexOf('/_next/data/') === -1 |
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
/*** function that used as middleware ***/ | |
accessToken: async (name) => { | |
if (typeof document === "undefined") return ""; | |
let token = document.cookie | |
.split(";") | |
.filter((cookie) => cookie.startsWith("token"))[0]; | |
if (!token) { | |
const response = await fetch("/api/refresh", { method: "POST" }); |
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 function resolvePluralForm(count: number) { | |
const lastNumber = count % 10 | |
const lastNumbers = count % 100 | |
if (lastNumber === 1 && lastNumbers !== 11) return 'one' | |
if (lastNumber > 1 && lastNumber < 5 && (lastNumbers < 10 || lastNumbers > 20)) return 'few' | |
return 'many' | |
} |
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
// v1 | |
const { data, error } = await supabase | |
.from('messages') | |
.select('*, users!inner(*)') | |
.eq('users.username', 'Jane') |
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
// @ts-expect-error effector does not have public types of withFactory | |
import { withFactory as withFactoryBase } from 'effector'; | |
type WithFactory = <R>({ | |
sid, | |
name, | |
loc, | |
method, | |
fn, | |
}: { |
OlderNewer