-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wait for Inertia router to be initialized
- Loading branch information
1 parent
75cc5e0
commit a8a0aab
Showing
3 changed files
with
58 additions
and
23 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 |
---|---|---|
|
@@ -19,7 +19,7 @@ public function run(): void | |
|
||
UserFactory::new() | ||
->recycle(Role::all()) | ||
->count(200) | ||
->count(20) | ||
->create(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,36 @@ | ||
import { router } from '@inertiajs/react' | ||
import { except, only, rejectNullValues } from './../../vue/src/helpers.js' | ||
|
||
export { except, only, rejectNullValues } | ||
/** | ||
* Resolves router.page from the Inertia router or waits for it to be available | ||
*/ | ||
function resolveInteriaPageFromRouter(waitForSeconds = 3, checkIntervalMilliseconds = 100) { | ||
const resolvePage = () => router.page || null | ||
|
||
return new Promise((resolve, reject) => { | ||
let page = resolvePage() | ||
|
||
if (page) { | ||
resolve(page) | ||
return | ||
} | ||
|
||
let maxAttempts = (waitForSeconds * 1000) / checkIntervalMilliseconds | ||
|
||
const interval = setInterval(() => { | ||
page = resolvePage() | ||
|
||
if (page) { | ||
clearInterval(interval) | ||
resolve(page) | ||
} | ||
|
||
if (--maxAttempts <= 0) { | ||
clearInterval(interval) | ||
reject(new Error('Inertia page not available')) | ||
} | ||
}, checkIntervalMilliseconds) | ||
}) | ||
} | ||
|
||
export { except, only, rejectNullValues, resolveInteriaPageFromRouter } |