refactor: move ListRenderingContext interface to types.d.ts and clean up processTemplateMarco.ts
This commit is contained in:
parent
828d6b0279
commit
3b344af52d
16
src/main.ts
16
src/main.ts
|
@ -1,21 +1,5 @@
|
||||||
import utils from './utils/index'
|
import utils from './utils/index'
|
||||||
|
|
||||||
interface ComponentOptions {
|
|
||||||
tag: string
|
|
||||||
template: string
|
|
||||||
style?: string
|
|
||||||
onMount?: (this: CustomElement) => void
|
|
||||||
onUnmount?: () => void
|
|
||||||
onAttributeChanged?: (
|
|
||||||
attrName: string,
|
|
||||||
oldValue: string,
|
|
||||||
newValue: string,
|
|
||||||
) => void
|
|
||||||
states?: Record<string, unknown>
|
|
||||||
statesListeners?: { [key: string]: (value: unknown) => void }
|
|
||||||
funcs?: { [key: string]: (...args: unknown[]) => void }
|
|
||||||
}
|
|
||||||
|
|
||||||
export default (options: ComponentOptions) => {
|
export default (options: ComponentOptions) => {
|
||||||
const {
|
const {
|
||||||
tag,
|
tag,
|
||||||
|
|
25
src/types.d.ts
vendored
25
src/types.d.ts
vendored
|
@ -2,3 +2,28 @@ interface CustomElement extends HTMLElement {
|
||||||
setState(key_path: string, value: unknown): void
|
setState(key_path: string, value: unknown): void
|
||||||
getState(key_path: string): unknown
|
getState(key_path: string): unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ListRenderingContext {
|
||||||
|
states: Record<string, unknown>
|
||||||
|
stateToElementsMap: Record<string, Set<HTMLElement>>
|
||||||
|
statesListeners: Record<string, (value: unknown) => void>
|
||||||
|
setState: (keyPath: string, value: unknown) => void
|
||||||
|
getState: (keyPath: string) => unknown
|
||||||
|
triggerFunc: (eventName: string, ...args: unknown[]) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ComponentOptions {
|
||||||
|
tag: string
|
||||||
|
template: string
|
||||||
|
style?: string
|
||||||
|
onMount?: (this: CustomElement) => void
|
||||||
|
onUnmount?: () => void
|
||||||
|
onAttributeChanged?: (
|
||||||
|
attrName: string,
|
||||||
|
oldValue: string,
|
||||||
|
newValue: string,
|
||||||
|
) => void
|
||||||
|
states?: Record<string, unknown>
|
||||||
|
statesListeners?: { [key: string]: (value: unknown) => void }
|
||||||
|
funcs?: { [key: string]: (...args: unknown[]) => void }
|
||||||
|
}
|
||||||
|
|
|
@ -307,16 +307,6 @@ function setupConditionRendering(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interface for list rendering context
|
|
||||||
interface ListRenderingContext {
|
|
||||||
states: Record<string, unknown>
|
|
||||||
stateToElementsMap: Record<string, Set<HTMLElement>>
|
|
||||||
statesListeners: Record<string, (value: unknown) => void>
|
|
||||||
setState: (keyPath: string, value: unknown) => void
|
|
||||||
getState: (keyPath: string) => unknown
|
|
||||||
triggerFunc: (eventName: string, ...args: unknown[]) => void
|
|
||||||
}
|
|
||||||
|
|
||||||
// Evaluate expressions using the item context
|
// Evaluate expressions using the item context
|
||||||
function evaluateExpressionWithItemContext(
|
function evaluateExpressionWithItemContext(
|
||||||
expression: string,
|
expression: string,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user