Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 5 additions & 3 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export interface Template {
isSVG?: boolean
}

export interface App<TRegorContext extends IRegorContext> {
export interface App<TRegorContext extends IRegorContext | object> {
context: TRegorContext
unmount: () => void
unbind: () => void
Expand All @@ -284,7 +284,9 @@ export interface App<TRegorContext extends IRegorContext> {
*
* @typeparam TContext - The type of context accepted by the component.
*/
export interface Component<TContext extends IRegorContext = IRegorContext> {
export interface Component<
TContext extends IRegorContext | object = IRegorContext,
> {
/**
* A function that returns the Regor context associated with the component.
*
Expand Down Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion src/app/ComponentHead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { type IRegorContext } from '../api/types'
import { removeNode } from '../cleanup/removeNode'
import { callUnmounted } from '../composition/callUnmounted'

export class ComponentHead<TContext extends IRegorContext = IRegorContext> {
export class ComponentHead<
TContext extends IRegorContext | object = IRegorContext,
> {
props: TContext

start: Comment
Expand Down
2 changes: 1 addition & 1 deletion src/app/RegorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class RegorConfig {
return obj
}

addComponent<TContext extends IRegorContext = IRegorContext>(
addComponent<TContext extends IRegorContext | object = IRegorContext>(
...components: Array<Component<TContext>>
): void {
for (const component of components) {
Expand Down
12 changes: 7 additions & 5 deletions src/app/createApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import { preprocess } from './preprocess-template'
import { RegorConfig } from './RegorConfig'
import { toFragment } from './toFragment'

export const createApp = <TRegorContext extends IRegorContext = IRegorContext>(
export const createApp = <
TRegorContext extends IRegorContext | object = IRegorContext,
>(
context: TRegorContext | Scope<TRegorContext>,
template: Template | string = { selector: '#app' },
config?: RegorConfig,
Expand Down Expand Up @@ -60,14 +62,14 @@ export const createApp = <TRegorContext extends IRegorContext = IRegorContext>(
}

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)
},
Expand Down
4 changes: 3 additions & 1 deletion src/app/createComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { RegorConfig } from './RegorConfig'
import { toFragment } from './toFragment'
import { toJsonTemplate } from './toJsonTemplate'

export const createComponent = <TContext extends IRegorContext = IRegorContext>(
export const createComponent = <
TContext extends IRegorContext | object = IRegorContext,
>(
template: Template | string,
options: CreateComponentOptions<TContext> | string[] = {},
): Component<TContext> => {
Expand Down
6 changes: 3 additions & 3 deletions src/composition/useScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import { popScope, pushScope, setScope } from './stack'

const scopeSymbol = Symbol('scope')

export const useScope = <TRegorContext extends IRegorContext>(
export const useScope = <TRegorContext extends IRegorContext | object>(
context: () => TRegorContext,
): Scope<TRegorContext> => {
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<TRegorContext>
;(result as any)[scopeSymbol] = 1
Expand Down