Skip to content

Instantly share code, notes, and snippets.

View srdjan's full-sized avatar

⊣˚∆˚⊢ srdjan

View GitHub Profile
@YBogomolov
YBogomolov / never-intersect.ts
Created May 15, 2019 12:17
Type-level laws: "function arguments should never intersect"
export type If<T, U, True, False> = [T] extends [U] ? True : False;
export type IfDef<T, Yep, Nope> = If<T, never, Nope, Yep>;
export type Intersect<A extends {}, B extends {}> =
Pick<A, Exclude<keyof A, Exclude<keyof A, keyof B>>> extends { [x: string]: never } ?
never :
Pick<A, Exclude<keyof A, Exclude<keyof A, keyof B>>>;
const f = <
A extends {},
B extends {},
@elierotenberg
elierotenberg / IMyProtocol.d.ts
Last active March 5, 2019 19:17
Statically typechecked serializable protocol
import { IProtocol, IRequestResponseMap, IEventMap } from "./IProtocol";
import { ISerializable } from "./ISerializable";
type RequestResponseMap = {
ping: {
RequestParams: {};
ResponseParams: {};
};
echo: {
RequestParams: ISerializable;
@busypeoples
busypeoples / TypeScriptFundamentals.ts
Last active June 21, 2022 14:57
TypeScript Fundamentals For JavaScript Developers
// TypeScript Fundamentals For JavaScript Developers
/*
Tutorial for JavaScript Developers wanting to get started with TypeScript.
Thorough walkthrough of all the basic features.
We will go through the basic features to gain a better understanding of the fundamentals.
You can uncomment the features one by one and work through this tutorial.
If you have any questions or feedback please connect via Twitter:
A. Sharif : https://twitter.com/sharifsbeat
*/
@tannerlinsley
tannerlinsley / hooks.js
Created January 25, 2019 17:00
useCancellable, useRefresh combo
const useCancellable = fn => {
const requestRef = useRef(0)
return async (...args) => {
// Keep track of latest promise ID
const id = Date.now()
requestRef.current = id
// Wait for resolution
const res = await fn(...args)
@lpalmes
lpalmes / react.md
Last active May 7, 2021 17:59
React and Reconcilers in Reason

React

This is the base of all projects and it will include the foundation for all potential react-based projects in Reason.

This base package should include a ReasonReact api to promote collaboration and familiarity with people using a ReasonReact, and for the modern world of React this should also include a Hooks api that currently revery uses.

React module

All blocks in Jsx are of type React.reactElement. This reactElement should represent:

@busypeoples
busypeoples / MonolithicComponentsComposableComponents.md
Last active September 24, 2022 17:14
Monolithic Components, Composable Components

Monolithic Components, Composable Components

Introduction

Building reusable UI components is a non trivial task, as we need to anticipate a number of things when planing for reuseability. On the one end of the spectrum we want to enable customization and on the other side we want to avoid developers doing the wrong thing, like breaking the component or displaying invalid states.

To get a better understanding of what we need to think about and consider upfront, we will build a non-trivial UI component, that displays tags. Our Tags component will take care of managing and displaying tags.

The following examples are all built with Tachyons and React, but these ideas apply to any UI component and any general styling approach.

@threepointone
threepointone / for-snook.md
Last active August 26, 2023 15:43
For Snook

https://twitter.com/snookca/status/1073299331262889984?s=21

‪“‬In what way is JS any more maintainable than CSS? How does writing CSS in JS make it any more maintainable?”

‪Happy to chat about this. There’s an obvious disclaimer that there’s a cost to css-in-js solutions, but that cost is paid specifically for the benefits it brings; as such it’s useful for some usecases, and not meant as a replacement for all workflows. ‬

‪(These conversations always get heated on twitter, so please believe that I’m here to converse, not to convince. In return, I promise to listen to you too and change my opinions; I’ve had mad respect for you for years and would consider your feedback a gift. Also, some of the stuff I’m writing might seem obvious to you; I’m not trying to tell you if all people of some of the details, but it might be useful to someone else who bumps into this who doesn’t have context)‬

So the big deal about css-in-js (cij) is selectors.

let UserContext = React.createContext();
class App extends React.Component {
state = {
user: null,
setUser: user => {
this.setState({ user });
}
};
@yelouafi
yelouafi / algebraic-effects-series-4.md
Last active March 1, 2024 15:31
Implementing Algebraic Effects and Handlers

Algebraic Effects in JavaScript part 4 - Implementing Algebraic Effects and Handlers

This is the final part of a series about Algebraic Effects and Handlers.

So we've come to the core topic. The reality is that we've already covered most of it in the previous parts. Especially, in the third part, where we saw delimited continuations at work.

@yelouafi
yelouafi / algebraic-effects-series-3.md
Last active April 19, 2023 06:07
Delimited Continuations