Skip to content

Instantly share code, notes, and snippets.

@fjahn
fjahn / beforeUnload.js
Created April 7, 2022 08:15
Block unload in Browser and Inertia Router using Vue
import { Inertia } from '@inertiajs/inertia'
import { onBeforeMount, onBeforeUnmount } from 'vue'
/**
* @param {() => boolean} shouldBlockUnload
* @param {string} message
* @returns void
*/
export function useBeforeUnload(
shouldBlockUnload,
@fjahn
fjahn / EventEmitter.ts
Created September 27, 2022 13:10
Typesafe Event Emitter
export class OpenEventEmitter<T> implements EventEmitter<T> {
private readonly handlers: { [eventName in keyof T]?: ((value: T[eventName]) => void)[] }
constructor() {
this.handlers = {}
}
getClosedEmitter(): EventEmitter<T> {
return this
}
@fjahn
fjahn / EnsureAppUrl.php
Created September 3, 2024 08:06
Laravel Middleware to redirect users to currently configured app url
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class EnsureAppUrl
{