Skip to content

Instantly share code, notes, and snippets.

Avatar

Paul Damnhorns nodkz

View GitHub Profile
@nodkz
nodkz / getNextPages.ts
Created August 4, 2022 19:25
Pages map generation for @module-federation/nextjs-mf
View getNextPages.ts
import fg from 'fast-glob';
/**
* From provided ROOT_DIR `scan` pages directory
* and return list of user defined pages
* (except special ones, like _app, _document, _error)
*/
export function getNextPages(cwd: string) {
// scan all files in pages folder except pages/api
let pageList = fg.sync('pages/**/*.{ts,tsx,js,jsx}', {
@nodkz
nodkz / proposal.md
Created April 28, 2022 21:20
Draft: Performance problems in Apollo Client v2, v3 and Relay. Why we need a new GraphQL Client?
View proposal.md

Performance problems in Apollo Client v2, v3 and Relay. Why we need a new GraphQL Client?

Both Apollo Client and Relay provide great State Managers for storing GraphQL responses with component updates on data changes. Under the hood they are using Cache Normalization that reduces data redundancy. More details can be found here for Apollo and here for Relay. This Normalization is a killer feature for Modern Web Apps - it helps to keep in sync displayable data of some entity in different parts of your application. But this Normalization has performance problems on big data sets.

Cache Normalization in Apollo Client 2 and Relay

Apollo Client was originally created as lightweight alternative of Relay. Apollo re-implemented basic functionality keeping in mind developer experience and bundle size. But conceptually Apollo Client 2

@nodkz
nodkz / readme.md
Created November 15, 2020 11:14
Что такое Стейт Менеджер для вас?
View readme.md

Что такое Стейт Менеджер для вас?

Чтоб вы поняли мою точку зрения, мне придется зайти с далека, чтобы вас ввести в свой контекст. Буду говорить просто и квадратно, и можно зацепиться за любое предложение и опровергнуть его.

Так вот начнем с далека. Человек изобрел транзистор. Из них собрали регистры, логичейские гейты AND, OR, XOR и пошла поехала булевая логика. Еще чутка напряглись и собрали калькуляторы и компьютеры. Поняли, что считает эта штука быстрее человека, и надо туда засовывать всё больше и больше вычислительной логики.

В 50-ых минули времена инструкций и чистого ассемблера, придумали языки программирования высокого уровня, типа Fortran, который позволял людям быстрее писать программы. Завезли туда переменные (VARIABLES) и начали писать безумные алгоритмы вычисления.

Так активно писали, что где-то в 60х запарились и придумали функции (FUNCTIONS), чтоб изолировать/инкапсулировать куски логики и алгоритмов. Привет функциональному подходу из 60х.

@nodkz
nodkz / connectionString.ts
Created October 14, 2020 19:55
Connection string
View connectionString.ts
export interface ConnectionStringHost {
host: string;
port?: number;
}
export interface ConnectionStringParameters {
scheme: string;
username?: string;
password?: string;
hosts: ConnectionStringHost[];
@nodkz
nodkz / fix-package-json.ts
Created June 6, 2019 11:55
Make fixed versions for packages in package.json according to installed packages (w/ Lerna support)
View fix-package-json.ts
import * as glob from 'glob';
import * as fs from 'fs';
import * as path from 'path';
async function changePackage(ppp: any) {
try {
const filesToUpdate: string[] = await new Promise((resolve, reject) => {
glob(ppp, function(err, files) {
if (err) return reject(err);
return resolve(files);
@nodkz
nodkz / component.js
Created August 25, 2018 05:24
Relay: unmask fragment by reading data from store
View component.js
function itemTrackingHelper(relayContext, item) {
const {title, description} = unmaskFragmentData({
relayContext,
relayData: item,
fragmentPropName: 'item',
fragment: itemTrackingHelperFragment
});
}
const itemTrackingHelperFragment = graphql`
@nodkz
nodkz / fixPackageRelayCompiler.1.4.js
Created July 5, 2018 09:34
Add optionalChaining to relay-compiler@1.4.1
View fixPackageRelayCompiler.1.4.js
/* @flow */
const fs = require('fs');
// Add support for optionalChaining in relay-compiler 1.4
const filename = './node_modules/relay-compiler/bin/relay-compiler';
fs.readFile(filename, 'utf8', (err, data) => {
if (err) {
return console.log(err);
@nodkz
nodkz / 1-server-generate-sign-url.js
Last active December 10, 2022 18:25
Upload image to S3 with resizing using lambda functions via hooks
View 1-server-generate-sign-url.js
/* @flow */
/* eslint-disable no-param-reassign */
import express, { type $Request, type $Response } from 'express';
import uniqid from 'uniqid';
import aws from 'aws-sdk';
export type SignResult = {
publicUrl: string,
signedUrl: string,
@nodkz
nodkz / client.js
Last active March 15, 2018 18:58
Proposal for react-relay-network-modern-ssr package
View client.js
// client
import { RelayNetworkLayer } from 'react-relay-network-modern';
import RelaySSR from 'react-relay-network-modern-ssr/client';
const relaySSR = new RelaySSR(window.relayData);
const network = new RelayNetworkLayer([
relaySSR.getMiddleware(),
]);
@nodkz
nodkz / LookupQueryRenderer.js
Created December 27, 2017 08:21
Relay.Modern query renderers
View LookupQueryRenderer.js
/* @flow */
/* eslint-disable no-use-before-define, react/no-unused-prop-types */
import * as React from 'react';
import areEqual from 'fbjs/lib/areEqual';
// forked from https://github.com/robrichard/relay-query-lookup-renderer
// import type { CacheConfig, Disposable } from 'RelayCombinedEnvironmentTypes';
// import type { RelayEnvironmentInterface as ClassicEnvironment } from 'RelayEnvironment';