This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { composeProviders, createProvider } from "compose-providers" | |
| import { LocalProvider, DateServiceProvider, LayoutProvider } from "providers" | |
| import { ReactNode } from "react" | |
| const Provider = composeProviders([ | |
| LocaleProvider | |
| createProvider(DateServiceProvider, { dateServiceType: "luxon" }), | |
| LayoutProvider, | |
| ]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class UrlBuilder { | |
| private fullUrl: string | |
| private queries: string[] = []; | |
| constructor(baseUrl: string, ...urls: string[]) { | |
| this.fullUrl = [baseUrl, ...urls].join("/"); | |
| } | |
| public addQuery(key: string, value: string | number | boolean) { | |
| this.queries.push(`${key}=${value}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { dispatchEvent } from "./event-control"; | |
| export const DispatchComponent = () => { | |
| const onClick = () => { | |
| dispatchEvent("ADD_COUNT") | |
| } | |
| return <button onClick={onClick}>Add</button> | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const removeAttribute = (dataArray: any[], attribute: string) => dataArray.map(({ [attribute]: _, ...rest }) => rest); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * A container object which may or may not contain a non-null value. | |
| * If a value is present, `isPresent()` returns `true` and `get()` returns the value. | |
| * | |
| * Additional methods that depend on the presence or absence of a contained value | |
| * are provided, such as `orElse()` and `ifPresent()`. | |
| * | |
| * @template T The type of the value | |
| * @example | |
| * const name = Optional.ofNullable(user?.name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Custom error types for domain-specific errors | |
| */ | |
| class DatabaseError extends Error { | |
| constructor(message: string, public readonly query?: string) { | |
| super(message); | |
| this.name = 'DatabaseError'; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // es mejor usar SETS que ARRAYS para combrobar si un valor existe dentro de un conjunto de valores | |
| // - evitas repetir valores | |
| // - es mas rapido de buscar con has que includes | |
| // con arrays | |
| const colors = ["red", "green", "blue"] as const; | |
| const isColors = colors.includes("red") // true | |
| // con sets | |
| const colors = new Set(["red", "green", "blue"] as const) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type NotNullish = {} | |
| const acceptsAnyNotNullishValue = (input: NotNullish) => {} | |
| acceptsAnyNotNullishValue("value") | |
| acceptsAnyNotNullishValue(123) | |
| acceptsAnyNotNullishValue(false) | |
| // you take a error | |
| acceptsAnyNotNullishValue(null) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //https://x.com/mattpocockuk/status/1821926395380986219 | |
| //No autocomplete for "primary" and "secondary" | |
| type Color = "primary" | "secondary" | string | |
| // Autocomplete "primary" and "secondary", but also allows any string | |
| type Color = "primary" | "secondary" | (string & {}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class NodeThree<T> { | |
| private id: Symbol; | |
| private nextIds: Symbol[] = []; | |
| private prevId: Symbol = Symbol() | |
| private value: T | |
| private constructor(id: Symbol, value: T) { | |
| this.id = id; | |
| this.value = value; | |
| } |