Skip to content

Instantly share code, notes, and snippets.

View zth's full-sized avatar

Gabriel Nordeborn zth

View GitHub Profile
@zth
zth / bun-headers.md
Last active November 1, 2023 13:57
TS -> ReScript examples

TypeScript:

/**
 * This Fetch API interface allows you to perform various actions on HTTP
 * request and response headers. These actions include retrieving, setting,
 * adding to, and removing. A Headers object has an associated header list,
 * which is initially empty and consists of zero or more name and value
 * pairs.
 *
 * You can add to this using methods like append()
@zth
zth / UntaggedUnionsReScript.md
Last active March 29, 2023 11:35 — forked from cristianoc/UntaggedUnionsReScript.md
Untagged Union Proposal for ReScript

Untagged Union Proposal for ReScript

Introduction

  • Brief introduction to ReScript
  • Motivation for untagged variants
  • High-level overview of the proposal

Detailed Design

module.exports = [
"and",
"as",
"asr",
"assert",
"begin",
"class",
"constraint",
"do",
"while",
@zth
zth / schema.graphql
Created February 10, 2020 19:01
Unions in Graphile?
type User {
id: ID!
name: String!
}
type Group {
id: ID!
name: String!
school: School!
}
@zth
zth / RelayUnusedFields.js
Created April 10, 2019 05:32
An example of where eslint-plugin-relay with unused-fields misses that fields are used in a function.
// collectConnectionNodes.js - Extracts and filters all nodes from a connection and returns it in a list, preserving the type information.
// @flow
export function collectConnectionNodes<T>(
connectionObj: ?{
+edges: ?$ReadOnlyArray<?{
+node: ?T
}>
}
): $ReadOnlyArray<T> {
if (connectionObj && connectionObj.edges && connectionObj.edges.length > 0) {
@zth
zth / Pagination.js
Created September 16, 2018 19:33
A typical pagination view.
// @flow
import { graphql, createPaginationContainer } from 'react-relay';
import type { UserPetsList_user } from './__generated__/UserPetsList_user.graphql';
import * as React from 'react';
import SinglePet from './SinglePet';
type Props = {|
relay: {
hasMore: () => boolean,
loadMore(pageSize: number, callback: ?(error: ?Error) => void): ?Object,
@zth
zth / App-tests.js
Created August 22, 2018 18:50
Tests for sample App component.
// @flow
import * as React from 'react';
import { queryMock } from '../../__testUtils__/queryMock'; // Or wherever your queryMock is located
import { App } from '../App';
import { render, wait } from 'react-testing-library';
describe('App', () => {
it('should render the current user count', async () => {
/**
* App fetches the query AppQuery. Here, we mock all requests for that query.
@zth
zth / App.js
Created August 22, 2018 18:41
Sample App component
// @flow
import * as React from 'react';
import { QueryRenderer, graphql } from 'react-relay';
import { environment } from '../config/createRelayEnvironment';
import type { AppQueryResponse } from './__generated__/AppQuery.graphql';
const query = graphql`
query AppQuery {
viewer {
id