-
-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2051 from inertiajs/takeover-scroll-restoration
[2.x] Take over scroll restoration from browser
- Loading branch information
Showing
15 changed files
with
242 additions
and
131 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
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
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
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
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,27 @@ | ||
export default class Queue<T> { | ||
protected items: (() => T)[] = [] | ||
protected processingPromise: Promise<void> | null = null | ||
|
||
public add(item: () => T) { | ||
this.items.push(item) | ||
return this.process() | ||
} | ||
|
||
public process() { | ||
this.processingPromise ??= this.processNext().then(() => { | ||
this.processingPromise = null | ||
}) | ||
|
||
return this.processingPromise | ||
} | ||
|
||
protected processNext(): Promise<void> { | ||
const next = this.items.shift() | ||
|
||
if (next) { | ||
return Promise.resolve(next()).then(() => this.processNext()) | ||
} | ||
|
||
return Promise.resolve() | ||
} | ||
} |
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
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
Oops, something went wrong.