-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add missing src/waiting-guard.mjs from template
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
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
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); | ||
} | ||
} | ||
} |