Skip to content

Commit 1da9a93

Browse files
committed
evalWithDocument + stricterd restricted globals
1 parent ccf5f80 commit 1da9a93

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

eslint.config.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,12 @@ export default tseslint.config(
225225
rules: {
226226
'no-restricted-globals': [
227227
'error',
228-
...['window', 'document', 'history', 'location'].map((name) => ({
229-
name,
230-
message: `Use the document-setup utility instead`,
231-
})),
228+
...['window', 'document', 'history', 'location', 'requestAnimationFrame'].map(
229+
(name) => ({
230+
name,
231+
message: `Use the document-setup utility instead`,
232+
}),
233+
),
232234
],
233235
},
234236
},

src/lib/utility/callback-attrs/mount.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const [processed, setProcessed] = createMagicProp<boolean>();
2525
* Special property to stock on window or document to mark that a mount request
2626
* has been scheduled.
2727
*/
28-
const [raf, setRaf] = createMagicProp<ReturnType<typeof requestAnimationFrame>>();
28+
const [raf, setRaf] = createMagicProp<number>();
2929

3030
/**
3131
* Process all mount attributes for a given node

src/lib/utility/document-setup.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { parentDocument } from '~/lib/utility/multi-view';
22

3-
export type DocumentSetupFunction = (document: Document) => void;
3+
export type DocumentCallbackFunction = (document: Document) => void;
44

55
/**
66
* Track all the setup functions (so we don't run twice and can re-run on all new
77
* open documents).
88
*/
9-
const setupFunctions = new Set<DocumentSetupFunction>();
9+
const setupFunctions = new Set<DocumentCallbackFunction>();
1010

1111
/**
1212
* Track which documents are open (so when adding a new setup function, we can call the
@@ -19,7 +19,7 @@ export const activeDocuments = new Set<Document>(parentDocument ? [parentDocumen
1919
* on the current document after idle period. Will also be triggered for new documents (if
2020
* doing child windows or something like that).
2121
*/
22-
export const registerDocumentSetup = (setup: DocumentSetupFunction) => {
22+
export const registerDocumentSetup = (setup: DocumentCallbackFunction) => {
2323
if (!setupFunctions.has(setup)) {
2424
setupFunctions.add(setup);
2525
for (const document of activeDocuments) {
@@ -42,3 +42,10 @@ export function registerDocument(document: Document) {
4242
}
4343
}
4444
}
45+
46+
/** Run a function on all active documents */
47+
export function evalWithDocument(cb: DocumentCallbackFunction) {
48+
for (const document of activeDocuments) {
49+
cb(document);
50+
}
51+
}

0 commit comments

Comments
 (0)