Skip to content

Commit

Permalink
refactor: Use only named exports, rather than a mix
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Apr 11, 2024
1 parent 7fa49c9 commit 6cf9462
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/hydrate.d.ts
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions src/hydrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -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';
9 changes: 3 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 1 addition & 1 deletion src/lazy.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentChildren, VNode } from 'preact';

export default function lazy<T>(load: () => Promise<{ default: T } | T>): T;
export function lazy<T>(load: () => Promise<{ default: T } | T>): T;

export function ErrorBoundary(props: { children?: ComponentChildren; onError?: (error: Error) => void }): VNode;
2 changes: 1 addition & 1 deletion src/lazy.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/prerender.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface PrerenderResult {
links?: Set<string>
}

export default function prerender(
export function prerender(
vnode: VNode,
options?: PrerenderOptions
): Promise<PrerenderResult>;
2 changes: 1 addition & 1 deletion src/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/router.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { h, 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() {} });

Expand Down

0 comments on commit 6cf9462

Please sign in to comment.