Skip to content

Commit

Permalink
Refactor variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
unlocomqx committed Apr 8, 2024
1 parent 4305d6f commit 9b2fe36
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/lib/client/superForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,25 +389,27 @@ try {
// No Storybook
}

const onDestroyCallbacks = new Set<() => void>();
const beforeNavigateCallbacks = new Set<(nav: BeforeNavigate) => Promise<void>>();
let lifeCycleHandlersInited = false;
const lifeCycleCallbacks = {
onDestroy: new Set<() => void>(),
beforeNavigate: new Set<(nav: BeforeNavigate) => Promise<void>>()
}
let componentInitialized = false;
function initLifeCycleCallbacks() {
if (lifeCycleHandlersInited) return;
lifeCycleHandlersInited = true;
if (componentInitialized) return;
componentInitialized = true;

onDestroy(() => {
for (const callback of onDestroyCallbacks) {
for (const callback of lifeCycleCallbacks.onDestroy) {
callback();
}
onDestroyCallbacks.clear();
lifeCycleCallbacks.onDestroy.clear();
});

beforeNavigate((nav: BeforeNavigate) => {
for (const callback of beforeNavigateCallbacks) {
for (const callback of lifeCycleCallbacks.beforeNavigate) {
callback(nav);
}
beforeNavigateCallbacks.clear();
lifeCycleCallbacks.beforeNavigate.clear();
});
}

Expand Down Expand Up @@ -548,7 +550,7 @@ export function superForm<

///// From here, form is properly initialized /////

onDestroyCallbacks.add(() => {
lifeCycleCallbacks.onDestroy.add(() => {
Unsubscriptions_unsubscribe();
NextChange_clear();
EnhancedForm_destroy();
Expand Down Expand Up @@ -1380,7 +1382,7 @@ export function superForm<
// Tainted check
const defaultMessage = 'Leave page? Changes that you made may not be saved.';
let forceRedirection = false;
beforeNavigateCallbacks.add(async (nav: BeforeNavigate) => {
lifeCycleCallbacks.beforeNavigate.add(async (nav: BeforeNavigate) => {
if (options.taintedMessage && !Data.submitting && !forceRedirection) {
if (Tainted_isTainted()) {
const { taintedMessage } = options;
Expand Down

0 comments on commit 9b2fe36

Please sign in to comment.