From 0a0bf83dae8ea003e771490f24184f2f6d27ff44 Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Thu, 11 Apr 2024 16:47:28 -0500 Subject: [PATCH] refactor: Use only named exports, rather than a mix --- src/hydrate.d.ts | 2 +- src/hydrate.js | 4 ++-- src/index.d.ts | 5 ++--- src/index.js | 9 +++------ src/lazy.d.ts | 2 +- src/lazy.js | 2 +- src/prerender.d.ts | 2 +- src/prerender.js | 2 +- test/router.test.js | 2 +- 9 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/hydrate.d.ts b/src/hydrate.d.ts index ace9158..f56e39d 100644 --- a/src/hydrate.d.ts +++ b/src/hydrate.d.ts @@ -1,3 +1,3 @@ import { ComponentChild } from 'preact'; -export default function hydrate(jsx: ComponentChild, parent?: Element | Document | ShadowRoot | DocumentFragment): void; +export function hydrate(jsx: ComponentChild, parent?: Element | Document | ShadowRoot | DocumentFragment): void; diff --git a/src/hydrate.js b/src/hydrate.js index 68d9375..d7e2cd8 100644 --- a/src/hydrate.js +++ b/src/hydrate.js @@ -2,8 +2,8 @@ import { render, hydrate as hydrativeRender } from 'preact'; let initialized; -/** @type {typeof render} */ -export default function hydrate(jsx, parent) { +/** @type {typeof hydrativeRender} */ +export function hydrate(jsx, parent) { if (typeof window === 'undefined') return; let isodata = document.querySelector('script[type=isodata]'); // @ts-ignore-next diff --git a/src/index.d.ts b/src/index.d.ts index 70ba4a2..1d8e633 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,4 +1,3 @@ -export { default as prerender } from './prerender.js'; export * from './router.js'; -export { default as lazy, ErrorBoundary } from './lazy.js'; -export { default as hydrate } from './hydrate.js'; +export * from './lazy.js'; +export * from './hydrate.js'; diff --git a/src/index.js b/src/index.js index 3bfc751..44fe534 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,4 @@ +// lack of wildcard export is intentional to avoid exposing `exec` export { Router, LocationProvider, useLocation, Route, useRoute } from './router.js'; -export { default as lazy, ErrorBoundary } from './lazy.js'; -export { default as hydrate } from './hydrate.js'; - -export function prerender(vnode, options) { - return import('./prerender.js').then(m => m.default(vnode, options)); -} +export * from './lazy.js'; +export * from './hydrate.js'; diff --git a/src/lazy.d.ts b/src/lazy.d.ts index 829cdf3..8805198 100644 --- a/src/lazy.d.ts +++ b/src/lazy.d.ts @@ -1,5 +1,5 @@ import { ComponentChildren, VNode } from 'preact'; -export default function lazy(load: () => Promise<{ default: T } | T>): T; +export function lazy(load: () => Promise<{ default: T } | T>): T; export function ErrorBoundary(props: { children?: ComponentChildren; onError?: (error: Error) => void }): VNode; diff --git a/src/lazy.js b/src/lazy.js index 9670e8d..17ce2c8 100644 --- a/src/lazy.js +++ b/src/lazy.js @@ -1,7 +1,7 @@ import { h, options } from 'preact'; import { useState, useRef } from 'preact/hooks'; -export default function lazy(load) { +export function lazy(load) { let p, c; return props => { const [, update] = useState(0); diff --git a/src/prerender.d.ts b/src/prerender.d.ts index b9958bc..104ba3d 100644 --- a/src/prerender.d.ts +++ b/src/prerender.d.ts @@ -9,7 +9,7 @@ export interface PrerenderResult { links?: Set } -export default function prerender( +export function prerender( vnode: VNode, options?: PrerenderOptions ): Promise; diff --git a/src/prerender.js b/src/prerender.js index be435bf..4a5d223 100644 --- a/src/prerender.js +++ b/src/prerender.js @@ -14,7 +14,7 @@ options.vnode = vnode => { * @param {object} [options] * @param {object} [options.props] Additional props to merge into the root JSX element */ -export default async function prerender(vnode, options) { +export async function prerender(vnode, options) { options = options || {}; const props = options.props; diff --git a/test/router.test.js b/test/router.test.js index 08a10b0..dcf56a0 100644 --- a/test/router.test.js +++ b/test/router.test.js @@ -3,7 +3,7 @@ import { h, hydrate, options, render } from 'preact'; import { useState } from 'preact/hooks'; import { html } from 'htm/preact'; import { LocationProvider, Router, useLocation, Route, useRoute } from '../src/router.js'; -import lazy, { ErrorBoundary } from '../src/lazy.js'; +import { lazy, ErrorBoundary } from '../src/lazy.js'; Object.defineProperty(window, 'scrollTo', { value() {} });