swyxio/svelte-actions

Save bytes on `preventTabClose`

Opened this issue · 1 comments

Sorry, I'm not on a device I can make a PR. A bit of bike-shedding to save bytes on preventTabClose.

Something along these lines:

// preventTabClose.js

function handler(e) {
	e.preventDefault();
	return '';
}

export const preventTabClose = (_, enabled) => {
    window[enabled 
				? "addEventListener"
				: "removeEventListener"
		]('beforeunload', handler)
    
	return {
        update: preventTabClose,
        destroy: () => preventTabClose(_, false),
    };
};

am fine with it. need tests more than i need to save bytes rn haha