-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(typechecking): fix typechecking on smart
- Loading branch information
1 parent
9fa8b2a
commit e23f12f
Showing
4 changed files
with
131 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { CcSmartContainer } from '../components/cc-smart-container/cc-smart-container.js'; | ||
import { COMPONENTS, CURRENT_CONTEXT, LAST_CONTEXT, META } from './smart-symbols.js'; | ||
|
||
export interface SmartContainer extends CcSmartContainer { | ||
[COMPONENTS]?: Map<SmartComponentCoreDefinition, Array<SmartComponent>>; | ||
[CURRENT_CONTEXT]?: SmartContext; | ||
} | ||
|
||
export interface SmartComponent extends Element { | ||
[LAST_CONTEXT]?: SmartContext; | ||
[META]?: Map<SmartComponentDefinition, { abortController?: AbortController }>; | ||
} | ||
|
||
export interface SmartComponentCoreDefinition { | ||
selector: string; | ||
params: Record<string, SmartDefinitionParam>; | ||
onConnect: (container: SmartContainer, component: SmartComponent) => void; | ||
onContextUpdate: (container: SmartContainer, component: SmartComponent, context: SmartContext) => void; | ||
onDisconnect: (container: SmartContainer, component: SmartComponent) => void; | ||
} | ||
|
||
export interface SmartComponentDefinition { | ||
selector: string; | ||
params: Record<string, SmartDefinitionParam>; | ||
onContextUpdate: (args: OnContextUpdateArgs) => void | Promise<void>; | ||
} | ||
|
||
export interface SmartDefinitionParam<TypeHint = unknown> { | ||
type: TypeHint; | ||
optional?: boolean; | ||
} | ||
|
||
export type SmartContext = Record<string, any>; | ||
|
||
export type OnEventCallback = (type: string, listener: (detail: any) => void) => void; | ||
|
||
export type UpdateComponentCallback<T = unknown> = (propertyName: string, property: CallbackOrObject<T>) => void; | ||
|
||
export interface OnContextUpdateArgs { | ||
container: SmartContainer; | ||
component: SmartComponent; | ||
context: SmartContext; | ||
signal: AbortSignal; | ||
onEvent: OnEventCallback; | ||
updateComponent: UpdateComponentCallback; | ||
} | ||
|
||
export type CallbackOrObject<T = unknown> = T | ((property: T) => void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const COMPONENTS = Symbol('COMPONENTS'); | ||
export const CURRENT_CONTEXT = Symbol('CURRENT_CONTEXT'); | ||
export const LAST_CONTEXT = Symbol('LAST_CONTEXT'); | ||
export const META = Symbol('META'); |