Skip to content

Instantly share code, notes, and snippets.

View kotoyama's full-sized avatar
🦆
Honk!

kotoyama

🦆
Honk!
View GitHub Profile
@den-churbanov
den-churbanov / react-router-effector-bind.ts
Last active January 31, 2024 10:46
Effector bindings for react-router-dom v.6.2.1
import { useContext } from 'react';
import { createStore, createEffect, createEvent, sample, attach, combine, restore } from 'effector';
import { spread, debug, not, and, empty, or } from 'patronum';
import { createGate, useGate } from 'effector-react';
import {
useLocation,
useNavigate,
matchPath,
generatePath,
RouteMatch,
import { createContext, ReactNode, useContext } from "react";
import {
ControllerInjectedResult,
Form as FormType,
useForm,
useFieldArray,
} from "effector-react-form";
import { FieldArray, ResultUseFieldArray } from "effector-react-form/types/ts";
export const FormContext = createContext<any>(null);
@epicbytes
epicbytes / example.api.ts
Last active May 30, 2024 12:18
NextJS Authorization Files
/*** 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" });
type AnyFunction = (...args: any[]) => any
function useEvent<T extends AnyFunction>(callback?: T) {
const ref = useRef<AnyFunction | undefined>(() => {
throw new Error("Cannot call an event handler while rendering.")
})
// Or useInsertionEffect if it's React 18
useLayoutEffect(() => {
ref.current = callback
})
@anchan828
anchan828 / README.md
Last active July 22, 2024 10:33
This is an improvement to allow @nestjs/typeorm@8.1.x to handle CustomRepository. I won't explain it specifically, but it will help in some way. https://github.com/nestjs/typeorm/pull/1233

You need to provide some classes and decorators yourself to maintain the same style as typeorm@2.x.

1. EntityRepository -> CustomRepository

@EntityRepository(UserEntity)
export class UserRepository extends Repository<UserEntity> {}

@kobzarvs
kobzarvs / app.tsx
Last active January 18, 2022 17:50
Простой пример использования effector-logger & effector-inspector без babel-plugin
import React from 'react';
import { useEvent, useStore } from 'effector-react';
import { $counter, dec, inc, reset } from './counter';
export const App = () => {
const counter = useStore($counter);
const api = useEvent({ inc, dec, reset });
return (
<div>
@longdog
longdog / cacheExample.ts
Last active February 3, 2022 22:01
effector fetch and cache
import { forward } from "effector";
import { createGate } from "effector-react";
import { createCached } from "store/helpers";
export const delegationSelectGage = createGate();
const [doFetch, $delegation, $loading] = createCached<void, Data[]>(
fetchDelegations,
"delegation"
);
@domosedov
domosedov / effector_kv.ts
Last active February 7, 2022 06:43
Effector KV
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>>;
@MrChocolatine
MrChocolatine / TS - More precise return type method Date#toISOString.d.ts
Last active July 12, 2024 00:28
TypeScript – How to accurately type dates in ISO 8601 format
// In TS, interfaces are "open" and can be extended
interface Date {
/**
* Give a more precise return type to the method `toISOString()`:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
*/
toISOString(): TDateISO;
}
type TYear = `${number}${number}${number}${number}`;
@dmjcomdem
dmjcomdem / grades.md
Last active July 16, 2024 05:40
Грейды для frontend-разработчиков

Level 1

  • Базовые знание диалекта Typescript, основных встроенных примитивов (Array, Object, Function, String, Date) и методов работы с ними, понимание контекста (this) и способов управления им
  • Базовые знания фреймворка React
  • Знание наиболее часто используемых Web API: fetch/XHR, Storage, PostMessage, DOM
  • Умение писать простейшие алгоритмы (поиск, сортировка, сравнение объектов) без требований к их оптимальности.
  • Навыки кроссбраузерной адаптивной верстки по макету с использованием существующего кода, знание CSS и препроцессора SCSS
  • Навыки отладки разметки в браузерах Chrome/Safari
  • Знание принципов работы HTTP, отличий между различными методами, принципов работы Cookies
  • Практическое владение лучшими практиками структурирования кода: SOLID/DRY/KISS и т.д.
  • Базовые знания git, понимание git flow