Skip to content

Instantly share code, notes, and snippets.

View pie6k's full-sized avatar

Adam Pietrasiak pie6k

View GitHub Profile
@pie6k
pie6k / product.ts
Last active April 20, 2018 10:39
typegql examples
import { ObjectType, Field } from 'typegql';
@ObjectType()
export class Product {
@Field()
id: number;
@Field()
price: number;
import { Schema, Query } from 'typegql';
import { Product } from './product.ts'
@Schema()
export class FirstSchema {
@Query()
findProductById(id: number): Product {
const foundProduct = new Product();
foundProduct.id = id;
foundProduct.price = 90;
import * as express from 'express';
import * as graphqlHTTP from 'express-graphql';
import { compileSchema } from 'typegql';
import { FirstSchema } from './simpleSchema.ts'
const schema = compileSchema(FirstSchema);
const app = express();
{
findProductById(id: 20) {
id
price
isExpensive
}
}
import { useEffect, useRef } from 'react';
export function useUnmountEffect(callback: () => void) {
const callbackRef = useRef(callback);
callbackRef.current = callback;
useEffect(() => {
return () => {
const callbackFunction = callbackRef.current;
@pie6k
pie6k / suspensify-promise.ts
Last active September 18, 2019 07:50
Suspensify Promise Typescript
type AllowedArg = number | string | boolean | null | undefined;
function stringifyArg(arg: AllowedArg) {
return `${arg}`;
}
function serializeArgs(args: AllowedArg[]) {
const argsLimiter = "<<<<***>>>>";
if (args.length === 0) {
@pie6k
pie6k / useShareForwardedRef.tsx
Created October 23, 2019 10:02
forwardRef hook
import React, { useRef, forwardRef, Ref, useEffect } from 'react';
import { TextInputProps, TextInput } from 'react-native';
import styled from 'styled-components/native';
interface Props extends TextInputProps {
showEditLabel?: boolean;
}
const Input = styled.TextInput``;
@pie6k
pie6k / rfc.jsx
Last active October 28, 2021 18:57
<Freeze /> React Component
/**
* Goal:
*
* Being able to freeze some part of react tree and stop all updates from 'react word' for part of the tree for some period of time.
* It would prevent ui from updating in any way (props change, state change, hooks change etc)
*
* Use case:
*
* Let's say there is tab based react-native app.
* All of the screens are rendered all the time, and by using some store (redux etc)
@pie6k
pie6k / useSuspend.tsx
Created October 29, 2019 19:37
useSuspend without waterfall
import { useRef } from 'react';
const noValueSymbol = Symbol();
function didBitsChange(oldBits: any[], newBits: any) {
return oldBits.some((oldBit, index) => !Object.is(oldBit, newBits[index]));
}
export function useSuspend<T>(
fetcher: () => Promise<T>,
@pie6k
pie6k / t
Created November 3, 2019 09:14
Test na mamę
"Test na mamę"
syn rozmawia z mamą o swojej aplikacji.
2 przykłady tej rozmowy, jedna w której syn oblewa "test na mamę" i druga w której zalicza.
W nawiasach są komentarza autora książki do tego co rozmawiają
syn: mamo, mam pomysł na biznes, mogę Ci o tym opowiedzieć? (mama myśli pewnie - o, mój synek! nie chce go urazić!)