-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
107 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import { templateByNode } from '../../lib/index.js'; | ||
import { signal, templateByNode } from '../../lib/index.js'; | ||
import { generateRandomName } from '../nested-signal/util.js'; | ||
|
||
templateByNode(document.body, { | ||
persons: [ | ||
{ name: 'Herbert' }, | ||
{ name: 'Klaus' }, | ||
{ name: 'Günther' }, | ||
] | ||
}) | ||
const persons = Array.from({ length: 500 }, () => { | ||
return { name: generateRandomName } | ||
}); | ||
|
||
templateByNode(document.body, { persons }); |
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,29 +1,29 @@ | ||
/** | ||
* @param { Element } node | ||
* @param { Element | undefined } hidden | ||
*/ | ||
export function notifyVisible(node, hidden = null) { | ||
hidden ??= node.closest('[hidden]'); | ||
/** @type { WeakMap<Node, ((value?: any) => void)[]> } */ | ||
const notifiers = new WeakMap(); | ||
|
||
return new Promise((resolve, reject) => { | ||
const observer = new MutationObserver(() => { | ||
hidden = node.closest('[hidden]'); | ||
|
||
if (hidden) { | ||
return observer.observe(hidden, { | ||
attributes: true, | ||
attributeFilter: ['hidden'] | ||
}); | ||
const observer = new IntersectionObserver((entries) => { | ||
|
||
for (const entry of entries) { | ||
if (entry.isIntersecting && notifiers.has(entry.target)) { | ||
for (const resolve of notifiers.get(entry.target)) { | ||
resolve(); | ||
} | ||
|
||
observer.disconnect(); | ||
|
||
resolve(); | ||
}); | ||
|
||
observer.observe(hidden, { | ||
attributes: true, | ||
attributeFilter: ['hidden'] | ||
}); | ||
notifiers.delete(entry.target); | ||
observer.unobserve(entry.target); | ||
} | ||
} | ||
}, { | ||
rootMargin: '256px', | ||
}); | ||
|
||
/** @param { Element } node */ | ||
export function notifyVisible(node) { | ||
return new Promise((resolve) => { | ||
const resolvers = notifiers.get(node) ?? []; | ||
|
||
resolvers.push(resolve); | ||
notifiers.set(node, resolvers); | ||
observer.observe(node); | ||
}); | ||
} |
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
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,17 @@ | ||
/** | ||
* @param {{ | ||
* href: string, | ||
* type?: string, | ||
* as: string, | ||
* crossOrigin?: string | ||
* }} attributes | ||
*/ | ||
export const preload = (attributes) => { | ||
const link = document.createElement('link'); | ||
|
||
Object.assign(link, attributes); | ||
|
||
link.rel = 'preload'; | ||
|
||
document.head.append(link); | ||
} |
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