Skip to content

Commit

Permalink
chore(useScript): prefer existing type
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Oct 29, 2023
1 parent 5105f55 commit f41a5ea
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/schema/src/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ResolvedScript, Script } from './'
import type { ActiveHeadEntry, CreateHeadOptions, HeadEntry, HeadEntryOptions, Unhead } from './head'
import type { HeadTag } from './tags'
import type { Script } from './'

export type HookResult = Promise<void> | void

Expand Down Expand Up @@ -33,7 +33,7 @@ export interface UseScriptOptions<T> extends Omit<HeadEntryOptions, 'transform'>
skipEarlyConnections?: boolean
use?: () => T | undefined | null
stub?: ((ctx: { script: ScriptInstance<T>; fn: string | symbol }) => any)
transform?: (script: ResolvedScript) => Promise<ResolvedScript> | ResolvedScript
transform?: (script: UseScriptInput) => Promise<UseScriptInput> | UseScriptInput
trigger?: 'idle' | 'manual' | Promise<void>
}

Expand Down Expand Up @@ -76,6 +76,6 @@ export interface HeadHooks {
'ssr:render': (ctx: { tags: HeadTag[] }) => HookResult
'ssr:rendered': (ctx: SSRRenderContext) => HookResult

'script:transform': (ctx: { script: ResolvedScript }) => HookResult
'script:transform': (ctx: { script: UseScriptInput }) => HookResult
'script:updated': (ctx: { script: ScriptInstance<any> }) => HookResult
}
1 change: 0 additions & 1 deletion packages/schema/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export type Link<E extends EntryAugmentation = {}> = MaybePromiseProps<LinkBase>
export type Meta<E extends EntryAugmentation = {}> = MaybePromiseProps<BaseMeta> & DataKeys & SchemaAugmentations['meta'] & DefinedValueOrEmptyObject<E>
export type Style<E extends EntryAugmentation = {}> = MaybePromiseProps<_Style> & DataKeys & SchemaAugmentations['style'] & DefinedValueOrEmptyObject<E>
export type Script<E extends EntryAugmentation = {}> = MaybePromiseProps<ScriptBase> & MaybeFunctionEntries<HttpEventAttributes> & DataKeys & SchemaAugmentations['script'] & DefinedValueOrEmptyObject<E>
export type ResolvedScript<E extends EntryAugmentation = {}> = ScriptBase & MaybeFunctionEntries<HttpEventAttributes> & DataKeys & SchemaAugmentations['script'] & DefinedValueOrEmptyObject<E>
export type Noscript<E extends EntryAugmentation = {}> = MaybePromiseProps<_Noscript> & DataKeys & SchemaAugmentations['noscript'] & DefinedValueOrEmptyObject<E>
export type HtmlAttributes<E extends EntryAugmentation = {}> = MaybePromiseProps<HtmlAttr> & DataKeys & SchemaAugmentations['htmlAttrs'] & DefinedValueOrEmptyObject<E>
export type BodyAttributes<E extends EntryAugmentation = {}> = MaybePromiseProps<BodyAttr> & MaybeFunctionEntries<BodyEvents> & DataKeys & SchemaAugmentations['bodyAttrs'] & DefinedValueOrEmptyObject<E>
Expand Down
4 changes: 2 additions & 2 deletions packages/unhead/src/composables/useScript.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NetworkEvents, hashCode } from '@unhead/shared'
import type { DomRenderTagContext, Head, HeadEntryOptions, ResolvedScript, Script, ScriptInstance, UseScriptInput, UseScriptOptions } from '@unhead/schema'
import type { DomRenderTagContext, Head, HeadEntryOptions, Script, ScriptInstance, UseScriptInput, UseScriptOptions } from '@unhead/schema'
import { getActiveHead } from './useActiveHead'

const UseScriptDefaults: Script = {
Expand All @@ -26,7 +26,7 @@ export function useScript<T>(input: UseScriptInput, _options?: UseScriptOptions<
return head._scripts[id]

async function transform(entry: Head): Promise<Head> {
const script = await (options.transform || (input => input))(entry.script![0] as ResolvedScript)
const script = await (options.transform || (input => input))(entry.script![0] as UseScriptInput)
const ctx = { script }
await head!.hooks.callHook('script:transform', ctx)
return { script: [ctx.script] }
Expand Down

0 comments on commit f41a5ea

Please sign in to comment.