Skip to content

Commit 19460d7

Browse files
authored
API: save a "flag" on window object (#474)
We need to find a way for people subscribing to the Read the Docs data ready event _after_ it was triggered. This is an idea about how to solve this use case. It adds a "flag" in the `window` object that users can check _before_ subscribing to that event to make usage of the data if the event was triggered already. * Reference: readthedocs/readthedocs.org#10648 (comment) * Example: https://github.com/readthedocs/test-builds/blob/full-feature/docs/static/readthedocs.js
1 parent 79b6e3b commit 19460d7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/readthedocs-config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ export function getReadTheDocsConfig(sendUrlParam) {
114114
// Expose `dataUser` if available or the `data` already requested.
115115
const dataEvent = dataUser !== undefined ? dataUser : data;
116116

117+
// Add the data to the window so scripts loaded after the initial
118+
// event was fired can still get access to the data
119+
globalThis.ReadTheDocsEventData = new ReadTheDocsEventData(dataEvent);
120+
117121
// Trigger the addons data ready CustomEvent to with the data the user is expecting.
118122
return dispatchEvent(
119123
EVENT_READTHEDOCS_ADDONS_DATA_READY,

0 commit comments

Comments
 (0)