Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Aug 15, 2024
1 parent ed6c5e4 commit b614355
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 175 deletions.
104 changes: 52 additions & 52 deletions src/Illuminate/Foundation/Vite.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function useManifestFilename($filename)
* @param array $config
* @return $this
*/
public function usePrefetchStrategy($strategy, $config)
public function usePrefetchStrategy($strategy, $config = [])
{
$this->prefetchStrategy = $strategy;

Expand Down Expand Up @@ -449,74 +449,74 @@ public function __invoke($entrypoints, $buildDirectory = null)
->pipe(fn ($assets) => with(Js::from($assets), fn ($assets) => match ($this->prefetchStrategy) {
'waterfall' => new HtmlString($base.<<<HTML
<script>
window.addEventListener('load', () => window.setTimeout(() => {
const linkTemplate = document.createElement('link')
linkTemplate.rel = 'prefetch'
<script>
window.addEventListener('load', () => window.setTimeout(() => {
const linkTemplate = document.createElement('link')
linkTemplate.rel = 'prefetch'
const makeLink = (asset) => {
const link = linkTemplate.cloneNode()
const makeLink = (asset) => {
const link = linkTemplate.cloneNode()
Object.keys(asset).forEach((attribute) => {
link.setAttribute(attribute, asset[attribute])
})
Object.keys(asset).forEach((attribute) => {
link.setAttribute(attribute, asset[attribute])
})
return link
}
return link
}
const loadNext = (assets, count) => window.setTimeout(() => {
if (count > assets.length) {
count = assets.length
const loadNext = (assets, count) => window.setTimeout(() => {
if (count > assets.length) {
count = assets.length
if (count === 0) {
return
}
if (count === 0) {
return
}
}
const fragment = new DocumentFragment
const fragment = new DocumentFragment
while (count > 0) {
const link = makeLink(assets.shift())
fragment.append(link)
count--
while (count > 0) {
const link = makeLink(assets.shift())
fragment.append(link)
count--
if (assets.length) {
link.onload = () => loadNext(assets, 1)
link.error = () => loadNext(assets, 1)
}
if (assets.length) {
link.onload = () => loadNext(assets, 1)
link.error = () => loadNext(assets, 1)
}
}
document.head.append(fragment)
})
document.head.append(fragment)
})
loadNext({$assets}, {$this->prefetchChunks})
}))
</script>
HTML),
'aggressive' => new HtmlString($base.<<<HTML
loadNext({$assets}, {$this->prefetchChunks})
}))
</script>
HTML),
'aggressive' => new HtmlString($base.<<<HTML
<script>
window.addEventListener('load', () => window.setTimeout(() => {
const linkTemplate = document.createElement('link')
linkTemplate.rel = 'prefetch'
<script>
window.addEventListener('load', () => window.setTimeout(() => {
const linkTemplate = document.createElement('link')
linkTemplate.rel = 'prefetch'
const makeLink = (asset) => {
const link = linkTemplate.cloneNode()
const makeLink = (asset) => {
const link = linkTemplate.cloneNode()
Object.keys(asset).forEach((attribute) => {
link.setAttribute(attribute, asset[attribute])
})
Object.keys(asset).forEach((attribute) => {
link.setAttribute(attribute, asset[attribute])
})
return link
}
return link
}
const fragment = new DocumentFragment
{$assets}.forEach((asset) => fragment.append(makeLink(asset)))
document.head.append(fragment)
}))
</script>
HTML),
}));
const fragment = new DocumentFragment
{$assets}.forEach((asset) => fragment.append(makeLink(asset)))
document.head.append(fragment)
}))
</script>
HTML),
}));
}

/**
Expand Down
Loading

0 comments on commit b614355

Please sign in to comment.