diff --git a/package.json b/package.json index 90ba5dc..0dafb91 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "regor", - "version": "1.3.0", + "version": "1.3.1", "description": "A modern UI framework for web and desktop applications, inspired by Vue's concepts and powered by simplicity and flexibility.", "author": "Ahmed Yasin Koculu", "license": "MIT", diff --git a/src/api/types.ts b/src/api/types.ts index 20fc0cf..1910cd1 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -273,7 +273,7 @@ export interface Template { isSVG?: boolean } -export interface App { +export interface App { context: TRegorContext unmount: () => void unbind: () => void @@ -284,7 +284,9 @@ export interface App { * * @typeparam TContext - The type of context accepted by the component. */ -export interface Component { +export interface Component< + TContext extends IRegorContext | object = IRegorContext, +> { /** * A function that returns the Regor context associated with the component. * @@ -319,7 +321,7 @@ export type OnMounted = () => void export type OnUnmounted = () => void export interface CreateComponentOptions< - TContext extends IRegorContext = IRegorContext, + TContext extends IRegorContext | object = IRegorContext, > { useInterpolation?: boolean diff --git a/src/app/ComponentHead.ts b/src/app/ComponentHead.ts index c17635c..f95f04b 100644 --- a/src/app/ComponentHead.ts +++ b/src/app/ComponentHead.ts @@ -2,7 +2,9 @@ import { type IRegorContext } from '../api/types' import { removeNode } from '../cleanup/removeNode' import { callUnmounted } from '../composition/callUnmounted' -export class ComponentHead { +export class ComponentHead< + TContext extends IRegorContext | object = IRegorContext, +> { props: TContext start: Comment diff --git a/src/app/RegorConfig.ts b/src/app/RegorConfig.ts index 0dbc6bc..07ad47a 100644 --- a/src/app/RegorConfig.ts +++ b/src/app/RegorConfig.ts @@ -98,7 +98,7 @@ export class RegorConfig { return obj } - addComponent( + addComponent( ...components: Array> ): void { for (const component of components) { diff --git a/src/app/createApp.ts b/src/app/createApp.ts index a1ad319..192ee7c 100644 --- a/src/app/createApp.ts +++ b/src/app/createApp.ts @@ -20,7 +20,9 @@ import { preprocess } from './preprocess-template' import { RegorConfig } from './RegorConfig' import { toFragment } from './toFragment' -export const createApp = ( +export const createApp = < + TRegorContext extends IRegorContext | object = IRegorContext, +>( context: TRegorContext | Scope, template: Template | string = { selector: '#app' }, config?: RegorConfig, @@ -60,14 +62,14 @@ export const createApp = ( } if (config.useInterpolation) interpolate(root, config) - const app = new RegorApp(context, root, config) + const app = new RegorApp(context as IRegorContext, root, config) app.__bind() addUnbinder(root, () => { - callUnmounted(context) + callUnmounted(context as IRegorContext) }) - callMounted(context) + callMounted(context as IRegorContext) return { - context, + context: context as TRegorContext, unmount: () => { removeNode(root) }, diff --git a/src/app/createComponent.ts b/src/app/createComponent.ts index 88bf149..a0ae46c 100644 --- a/src/app/createComponent.ts +++ b/src/app/createComponent.ts @@ -13,7 +13,9 @@ import { RegorConfig } from './RegorConfig' import { toFragment } from './toFragment' import { toJsonTemplate } from './toJsonTemplate' -export const createComponent = ( +export const createComponent = < + TContext extends IRegorContext | object = IRegorContext, +>( template: Template | string, options: CreateComponentOptions | string[] = {}, ): Component => { diff --git a/src/composition/useScope.ts b/src/composition/useScope.ts index f354b07..a76ec2f 100644 --- a/src/composition/useScope.ts +++ b/src/composition/useScope.ts @@ -5,16 +5,16 @@ import { popScope, pushScope, setScope } from './stack' const scopeSymbol = Symbol('scope') -export const useScope = ( +export const useScope = ( context: () => TRegorContext, ): Scope => { try { pushScope() const ctx = context() - setScope(ctx) + setScope(ctx as IRegorContext) const result = { context: ctx, - unmount: () => callUnmounted(ctx), + unmount: () => callUnmounted(ctx as IRegorContext), [scopeSymbol]: 1, } as unknown as Scope ;(result as any)[scopeSymbol] = 1