Skip to content

Commit

Permalink
add missing src/waiting-guard.mjs from template
Browse files Browse the repository at this point in the history
  • Loading branch information
arlac77 committed Jun 20, 2024
1 parent 128a39a commit 9938594
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/waiting-guard.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Guard } from "./guard.mjs";

/**
* Shows a component during transition.
* @param {SvelteComponent} component to show up during th transition
* @param {number} rampUpTime initial delay for the componnt to show up
*/
export class WaitingGuard extends Guard {

#component;
#rampUpTime;

constructor(component, rampUpTime = 300) {
super();
this.#component = component;
this.#rampUpTime = rampUpTime;
}

async enter(transition) {
transition.timeoutID = setTimeout(() => {
transition.timeoutID = undefined;
transition.component = this.#component;
}, this.#rampUpTime);
}

async leave(transition) {
if (transition.timeoutID) {
clearTimeout(transition.timeoutID);
}
}
}

0 comments on commit 9938594

Please sign in to comment.