Add statesListeners to ComponentOptions and trigger state update events in setState
This commit is contained in:
parent
9d62c64b0f
commit
b9cb3f455c
10
src/main.ts
10
src/main.ts
|
@ -11,10 +11,11 @@ interface ComponentOptions {
|
||||||
onUnmount?: () => void
|
onUnmount?: () => void
|
||||||
onAttributeChanged?: (attrName: string, oldValue: string, newValue: string) => void
|
onAttributeChanged?: (attrName: string, oldValue: string, newValue: string) => void
|
||||||
states?: Record<string, any>
|
states?: Record<string, any>
|
||||||
|
statesListeners?: { [key: string]: (value: any) => void }
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (options: ComponentOptions) => {
|
export default (options: ComponentOptions) => {
|
||||||
const { tag, template, style, onMount, onUnmount, onAttributeChanged, states } = options
|
const { tag, template, style, onMount, onUnmount, onAttributeChanged, states, statesListeners } = options
|
||||||
const componentRegistry = new Map()
|
const componentRegistry = new Map()
|
||||||
componentRegistry.set(tag, options)
|
componentRegistry.set(tag, options)
|
||||||
|
|
||||||
|
@ -41,7 +42,12 @@ export default (options: ComponentOptions) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: trigger dom updates
|
// TODO: trigger dom updates
|
||||||
// TODO: trigger state update events
|
|
||||||
|
// trigger state update events
|
||||||
|
if (statesListeners && statesListeners[keyPath]) {
|
||||||
|
statesListeners[keyPath](value)
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
get: (target: Record<string, any>, keyPath: string) => {
|
get: (target: Record<string, any>, keyPath: string) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user