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 Subscriber<TData> = (data: TData) => void; | |
interface IPublisher<TEvent, TData> { | |
subscribe(event?: TEvent): (subscriber: Subscriber<TData>) => () => void; | |
notify(event: TEvent, data: TData): void; | |
} | |
export class Publisher<TEvent, TData> implements IPublisher<TEvent, TData> { | |
protected subscribers: { event: TEvent; subscriber: Subscriber<TData> }[] = []; |
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
export abstract class Mapper<TDomain, TDto = unknown> { | |
// public static map: Mapper<TDomain, TDto>; Add this property to a mapper to access methods like they were static. | |
public abstract toDto?: (domain: TDomain) => TDto; | |
public abstract toDomain?: (dto: TDto) => TDomain; | |
} |
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
export const nbspScript = (text: string) => { | |
const input = text.split(' '); | |
let output = input[input.length - 1]; | |
for (let index = 0; index < input.length; index++) { | |
const reversedIndex = input.length - index - 1; | |
const word = input[reversedIndex]; | |
if (reversedIndex !== input.length - 1) { | |
if (word.length > 1) { | |
output = `${word} ${output}`; | |
} else { |
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 { Context, useContext } from 'react'; | |
export const useContextSafe = <TContext>( | |
context: Context<TContext> | |
): NonNullable<TContext> => { | |
const ctxValue = useContext(context); | |
if (!ctxValue) { | |
throw new Error( | |
`Cannot read ${context.displayName} context. You may have forgot to wrap it with the Provider` | |
); |