Skip to content

Instantly share code, notes, and snippets.

@joepie91
joepie91 / es-modules-are-terrible-actually.md
Last active April 25, 2024 08:34
ES Modules are terrible, actually

ES Modules are terrible, actually

This post was adapted from an earlier Twitter thread.

It's incredible how many collective developer hours have been wasted on pushing through the turd that is ES Modules (often mistakenly called "ES6 Modules"). Causing a big ecosystem divide and massive tooling support issues, for... well, no reason, really. There are no actual advantages to it. At all.

It looks shiny and new and some libraries use it in their documentation without any explanation, so people assume that it's the new thing that must be used. And then I end up having to explain to them why, unlike CommonJS, it doesn't actually work everywhere yet, and may never do so. For example, you can't import ESM modules from a CommonJS file! (Update: I've released a module that works around this issue.)

And then there's Rollup, which apparently requires ESM to be u

@kourge
kourge / jslike.code-snippets
Created March 3, 2021 23:20
a VS Code snippet for typing in JS imports module-first, like the order in Python
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
"Named import": {
"scope": "javascript,javascriptreact,typescript,typescriptreact",
"prefix": "from",
@ClickerMonkey
ClickerMonkey / types.ts
Last active February 6, 2024 07:21
Typescript Helper Types
// when T is any|unknown, Y is returned, otherwise N
type IsAnyUnknown<T, Y, N> = unknown extends T ? Y : N;
// when T is never, Y is returned, otherwise N
type IsNever<T, Y = true, N = false> = [T] extends [never] ? Y : N;
// when T is a tuple, Y is returned, otherwise N
// valid tuples = [string], [string, boolean],
// invalid tuples = [], string[], (string | number)[]
@adamkl
adamkl / AppContextProvider.tsx
Created February 10, 2020 22:20
xState service layer
import React from "react";
import { createUserSessionService } from "services/UserSessionService";
import { createNavService } from "services/NavService";
// Wiring up our "IOC container"
const userSessionService = createUserSessionService();
// NavService depends on UserSessionService
const navService = createNavService(userSessionService);
@mikalv
mikalv / cheatsheet.md
Created November 26, 2019 23:53 — forked from sshkarupa/cheatsheet.md
Elixir cheat sheet

Elixir Cheat Sheet

Getting started

Hello world

# hello.exs
defmodule Greeter do
 def greet(name) do
@c9s
c9s / .babelrc
Last active October 21, 2023 14:04
webpack + babel + typescript + es6 - total solutions!
{
"presets": ["es2015"],
"plugins": ["transform-runtime"]
}
@gaearon
gaearon / connect.js
Last active April 11, 2024 06:46
connect.js explained
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (
@kolodny
kolodny / actions.js
Last active May 17, 2018 18:42
testing redux thunk middleware
export const doTheThing = () => (dispatch, getState) => {
const users = getState();
dispatch({
type: 'THE_THING',
users,
});
};
@revolunet
revolunet / python-es6-comparison.md
Last active April 22, 2024 19:22
# Python VS JavaScript ES6 syntax comparison

Python VS ES6 syntax comparison

Python syntax here : 2.7 - online REPL

Javascript ES6 via Babel transpilation - online REPL

Imports

import math
@dankeezer
dankeezer / kiosk
Last active September 12, 2018 15:09
AppleScript + directions to auto-launch Chrome in full-screen at startup.
# I'd just give you the .app but you need to change the code to the correct URL.
## Create the kiosk App
# using AppleScript Editor create a script called “kiosk”
# here’s the code
do shell script "open '/Applications/Google Chrome.app' http://phhhoto.com/d/websterhall/5/2"
tell application "Google Chrome" to activate