Skip to content

Instantly share code, notes, and snippets.

@intrnl
intrnl / _treeshake-class-methods.ts
Last active Sep 3, 2021
Tree-shakeable class methods
View _treeshake-class-methods.ts
import { Module } from './module';
export class Foo extends Module {
_foo = 'foo';
}
export class Bar extends Module {
_bar = 'bar';
}
View live-fragment.js
export class LiveFragment {
parentNode = null;
markerNode = document.createComment('fragment');
childNodes = [];
static from (content) {
let instance = new TemplateFragment();
let fragment = content.cloneNode(true);
View _promise-attempt.ts
type Callable = (...args: any[]) => any;
export function attempt<T extends Callable>(fn: T, ...args: Parameters<T>): Promise<ReturnType<T>> {
return new Promise((resolve) => fn(...args));
}
@intrnl
intrnl / discord-compact-chat.css
Last active Sep 22, 2021
Middle ground between compact and cozy chat layout
View discord-compact-chat.css
.theme-light {
--background-mentioned: hsla(38, calc(var(--saturation-factor, 1) * 95.7%), 54.1%, 0.25);
}
/** Chat scroller */
.auto-Ge5KZx, .auto-Ge5KZx.fade-2kXiP2:hover, .auto-Ge5KZx.scrolling-1Cdwk- {
scrollbar-color: var(--scrollbar-auto-scrollbar-color-thumb) transparent;
}
/** Chat spacer */
@intrnl
intrnl / tabination-context.jsx
Last active Jun 22, 2021
React tabination context
View tabination-context.jsx
import React from 'react';
////// Core component
/// <Tabination />
let TabinationContext = React.createContext(null);
export function Tabination (props) {
let { children } = props;
let [current, setCurrent] = React.useState();
View direct-dom-diff.js
let curr_document = null;
let curr_parent = null;
let curr_node = null;
let curr_focus_path = null;
function assert (statement, message) {
if (!statement) throw new Error(message);
}
@intrnl
intrnl / react-asset-loader.js
Created Jun 9, 2021
React concurrent asset loader
View react-asset-loader.js
import { unstable_getCacheForType } from 'react';
import deepEqual from 'fast-deep-equal';
let hasArgs = (args) => (record) => deepEqual(args, record.args);
class Asset {
#loader;
#lifespan;
View patch_trace.js
// monkey patches all class methods for tracing calls
// not made for async methods
function patch_trace (cl, depth = Infinity) {
let proto = cl.prototype;
do {
if (!depth-- || proto === Object.prototype) break;
let name = proto.constructor.name;
View eventemitter.js
class EventEmitter {
#events = new EventTarget();
#map = new WeakMap();
on (type, listener, opts = {}) {
let { once = false } = opts;
let fn = this.#map.get(listener);
if (!fn) {
fn = (ev) => listener(...ev.detail);
View holder.md

i hold intrnl#7717 754023929848397824

prev .intrnl#6380 443765978132643850

are you happy now avi