Skip to content

Instantly share code, notes, and snippets.

View guiseek's full-sized avatar
🌱
Nós poderíamos ser muito melhores se não quiséssemos ser tão bons.

Guilherme Siquinelli guiseek

🌱
Nós poderíamos ser muito melhores se não quiséssemos ser tão bons.
View GitHub Profile
@guiseek
guiseek / abstract.ts
Created November 14, 2024 08:11
Create providers
export type Abstract<T = any> = abstract new (...params: any[]) => T;
import {Abstract} from './abstract'
import {Type} from './type'
export type AbstractConstructorParams<T extends Type> =
ConstructorParameters<T> extends {
length: 1
}
? [Abstract<ConstructorParameters<T>[0]>]
: ConstructorParameters<T> extends {length: 2}
? [
@guiseek
guiseek / action.ts
Created August 15, 2024 07:49
State
import {Callback} from './callback'
export class Action<T> {
constructor(public type: string, public value: T) {}
}
export const createAction = <T>(type: string) => {
return class extends Action<T> {
constructor(value: T) {
super(type, value)
@guiseek
guiseek / merge.ts
Created August 3, 2024 22:59
merge form input events
interface Callback<T> {
(value: T): void;
}
function merge<T>(form: HTMLFormElement) {
const watchers = new Set<Callback<T>>();
const fields = Array.from(form.elements) as HTMLInputElement[];
const value = <T>(form: HTMLFormElement) => {
const data = new FormData(form);
@guiseek
guiseek / define.ts
Created June 11, 2024 17:31
Define typed custom element
type Tag = `${string}-${string}`;
type TagMap = HTMLElementTagNameMap;
interface CustomElement<T> extends CustomElementConstructor {
new (...params: any[]): T;
}
function define<S extends Tag, K extends keyof TagMap>(selector: S, is?: K) {
return (target: CustomElement<TagMap[K]>) => {
export type ArrayInfer<T> = T extends (infer U)[] ? U : never
@guiseek
guiseek / di.ts
Created May 18, 2024 05:16
DI - use / add / set
const container = new Map()
const relations = new Map()
export const use = <T>(type: Key<T>): T => {
const concrete = container.get(type)
if (!concrete) throw `Provider ${type.name} não registrado`
return concrete
}
const provide = <T>({for: key, use}: For<T>) => {
export const App = () => {
const title = "TSX Vanilla";
return (
<>
<h1>{title}</h1>
</>
);
};
@guiseek
guiseek / index.html
Created May 4, 2024 05:04
Audio player vanila HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/ts.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + TS</title>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;