Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public addEventListener (type: string, handler: EventHandler, options?: boolean | AddEventListenerOptions) {
type = type.toLowerCase()
const handlers = this.__handlers[type]
let isCapture = Boolean(options)
let isOnce = false
if (isObject(options)) {
isCapture = Boolean(options.capture)
isOnce = Boolean(options.once)
}
if (isOnce) {
const wrapper = function () {
handler.apply(this, arguments) // this 指向 Element
this.removeEventListener(type, wrapper)
}
this.addEventListener(type, wrapper, {
...(options as AddEventListenerOptions),
once: false
})
return
}
style.cssText = value
} else {
if (isString(oldValue)) {
style.cssText = ''
oldValue = null
}
if (isObject(oldValue)) {
for (const i in oldValue) {
if (!(value && i in (value as StyleValue))) {
setStyle(style, i, '')
}
}
}
if (isObject(value)) {
for (const i in value) {
if (!oldValue || value[i] !== (oldValue as StyleValue)[i]) {
setStyle(style, i, value[i])
}
}
}
}
} else if (isEventName(name)) {
setEvent(dom, name, value, oldValue)
} else if (
!isFunction(value) &&
name !== 'dangerouslySetInnerHTML' // TODO: 实现 innerHTML
) {
if (value == null) {
dom.removeAttribute(name)
} else {
name === 'key' ||
name === 'children' ||
name === 'ref'
) {
// skip
} else if (name === 'style') {
const style = dom.style
if (isString(value)) {
style.cssText = value
} else {
if (isString(oldValue)) {
style.cssText = ''
oldValue = null
}
if (isObject(oldValue)) {
for (const i in oldValue) {
if (!(value && i in (value as StyleValue))) {
setStyle(style, i, '')
}
}
}
if (isObject(value)) {
for (const i in value) {
if (!oldValue || value[i] !== (oldValue as StyleValue)[i]) {
setStyle(style, i, value[i])
}
}
}
}
} else if (isEventName(name)) {