Inspired by https://twitter.com/TkDodo/status/1734255363266843017?t=dOhCHPJJMd2bq2A8VK8R-A&s=19
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 { Page } from '@playwright/test'; | |
export async function transformWebsocketMessage( | |
page: Page, | |
fn: <TMessage extends Record<string, unknown>>( | |
url: string, | |
message: TMessage | |
) => TMessage | |
) { | |
fn = fn || ((url, message) => message); |
This file contains 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
// Use a conditional, because You may not want to provide swagger documentation in public environments | |
if (_configuration.GetValue<bool>("SwaggerConfiguration:EnableSwagger")) | |
{ | |
services.AddEndpointsApiExplorer(); | |
services.AddSwaggerGen(options => { | |
options.AddCustomIds(); | |
options.AddMetadata(typeof(Program)); | |
options.SchemaFilter<NullableEnumSchemaFilter>(); | |
options.SchemaFilter<RequiredPropertiesSchemaFilter>(); |
This file contains 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 { camelCase, pascalCase, snakeCase } from "change-case"; | |
type CamelToPascalCase<S extends string> = S extends `${infer F}${infer R}` | |
? `${Capitalize<F>}${R}` | |
: S; | |
type PascalToCamelCase<S extends string> = S extends `${infer F}${infer R}` | |
? `${Uncapitalize<F>}${R}` | |
: S; | |
type SnakeToCamelCase<S extends string> = S extends `${infer F}_${infer R}` | |
? `${Uncapitalize<F>}${Capitalize<SnakeToCamelCase<R>>}` |
This file contains 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 httpStatus from "http-status"; | |
export const makeError = <TErrorName extends string>( | |
name: TErrorName, | |
message?: string | |
) => ({ | |
name, | |
message, | |
}); |
This file contains 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 Prettify<T> = { | |
[K in keyof T]: T[K]; | |
}; | |
export type Model<T> = Prettify< | |
T & { | |
_id: string; | |
createdAt: Date | string; | |
updatedAt: Date | string; | |
deletedAt?: Date | string | null; |
This file contains 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 CamelToSnakeCase<S extends string> = S extends `${infer T}${infer U}` | |
? `${T extends Capitalize<T> ? '_' : ''}${Lowercase<T>}${CamelToSnakeCase<U>}` | |
: S | |
type SnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}` | |
? `${T}${Capitalize<SnakeToCamelCase<U>>}` | |
: S | |
type StringKeys<TEntity extends {}> = { | |
[key in keyof TEntity]: key extends string ? key : never | |
}[keyof TEntity] | |
type IsLiteral<TValue> = TValue extends string | number | boolean | symbol |
Here, we'll explore loosely coupling react hooks with dependency inversion as a way to manage side effects.
NB: The hooks code given here, uses react-query hooks for simplicity cos I'm rushing to write this. I hope that's not a problem. Perhaps, someone will write the equivalent implementations using out-of-the-box react hooks.
We'll consider a simple react hook, that fetches a list of users in two ways:
const useFetchUsers = () => {
This file contains 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
/** | |
* @typedef {object} AWSCloudfrontMessageEvent | |
* @property {AWSCloudfrontEventRecord[]} Records | |
*/ | |
/** | |
* @typedef {object} AWSCloudfrontEventRecord | |
* @property {object} cf | |
* @property {{ distributionId: string, eventType: string, requestId: string, distributionDomainName: string }} cf.config | |
* @property {AWSCloudfrontRequest} cf.request |
NewerOlder