Skip to content

Commit f89ce42

Browse files
committed
Better global types
1 parent ca01364 commit f89ce42

3 files changed

Lines changed: 9 additions & 15 deletions

File tree

packages/diffhtml/lib/index.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,22 @@ api['toString'] = toString;
3333
api['html'] = html;
3434
api['Internals'] = Internals;
3535

36-
/** @type {any} */
37-
const global = globalThis;
38-
3936
// Bind the API into the global scope. Allows middleware and other code to
4037
// reference the core API. Once import maps are more mainstream, we can
4138
// deprecate this.
4239
if ($$diffHTML in globalThis) {
43-
const existingApi = global[$$diffHTML];
40+
const existingApi = globalThis[$$diffHTML];
4441

4542
if (VERSION !== existingApi['VERSION']) {
4643
console.log(`Loaded ${VERSION} after ${existingApi.VERSION}`);
4744
}
4845
}
4946

50-
global[$$diffHTML] = api;
47+
globalThis[$$diffHTML] = api;
5148

5249
// Automatically hook up to DevTools if they are present.
53-
if (global.devTools) {
54-
global.unsubscribeDevTools = use(global.devTools(Internals));
50+
if (globalThis.devTools) {
51+
globalThis.unsubscribeDevTools = use(globalThis.devTools(Internals));
5552
}
5653

5754
export {

packages/diffhtml/lib/lite.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,21 @@ api.innerHTML = innerHTML;
2828
api.html = createTree;
2929
api.Internals = internals;
3030

31-
/** @type {any} */
32-
const global = globalThis;
33-
3431
// Bind the API into the global scope. Allows middleware and other code to
3532
// reference the core API.
3633
if ($$diffHTML in globalThis) {
37-
const existingApi = global[$$diffHTML];
34+
const existingApi = globalThis[$$diffHTML];
3835

3936
if (VERSION !== existingApi.VERSION) {
4037
console.log(`Loaded ${VERSION} after ${existingApi.VERSION}`);
4138
}
4239
}
4340

44-
global[$$diffHTML] = api;
41+
globalThis[$$diffHTML] = api;
4542

4643
// Automatically hook up to DevTools if they are present.
47-
if (global.devTools) {
48-
global.unsubscribeDevTools = use(global.devTools(internals));
44+
if (globalThis.devTools) {
45+
globalThis.unsubscribeDevTools = use(globalThis.devTools(internals));
4946
}
5047

5148
export {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @type {{
3-
* [key: string]: any;
3+
* [key: string | symbol]: any;
44
* }}
55
*/
66
export default typeof global === 'object' ? global : (typeof window === 'object' ? window : self) || {};

0 commit comments

Comments
 (0)