-
Основные типы и структуры данных
- number, string, boolean, undefined
- object, array, null
- symbol, bigint, ...
-
типы переменных
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
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
/*** 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
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
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
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
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
import * as React from "react"; | |
import type { Scope } from "effector"; | |
import { fork, serialize } from "effector"; | |
let clientScope: Scope; | |
const initializeScope = (initialData: Record<string, unknown>) => { | |
let scope = fork({ | |
values: { | |
...(clientScope ? serialize(clientScope) : {}), |
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
// get data from clock & source | |
guard({ | |
source: sample( | |
$source, | |
clock, | |
(source, clock) => ({ source, clock }) | |
), | |
… | |
}) |
NewerOlder