types: improve typing (#309)
This commit is contained in:
parent
b54c05f751
commit
32499b16e7
@ -17,7 +17,7 @@ const bracketsRE = /^\[|\]$/g
|
|||||||
// e.g.
|
// e.g.
|
||||||
// - createObjectMatcher({ 'foo': '[bar]' }) matches { foo: bar }
|
// - createObjectMatcher({ 'foo': '[bar]' }) matches { foo: bar }
|
||||||
// - createObjectMatcher({ '[foo]': 'bar' }) matches { [foo]: "bar" }
|
// - createObjectMatcher({ '[foo]': 'bar' }) matches { [foo]: "bar" }
|
||||||
export function createObjectMatcher(obj: any) {
|
export function createObjectMatcher(obj: Record<string, any>) {
|
||||||
return {
|
return {
|
||||||
type: NodeTypes.JS_OBJECT_EXPRESSION,
|
type: NodeTypes.JS_OBJECT_EXPRESSION,
|
||||||
properties: Object.keys(obj).map(key => ({
|
properties: Object.keys(obj).map(key => ({
|
||||||
|
2
packages/runtime-dom/jsx.d.ts
vendored
2
packages/runtime-dom/jsx.d.ts
vendored
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
interface HTMLAttributes {
|
interface HTMLAttributes {
|
||||||
class?: any
|
class?: any
|
||||||
style?: string | { [key: string]: string | number }
|
style?: string | Partial<CSSStyleDeclaration>
|
||||||
accesskey?: string
|
accesskey?: string
|
||||||
contenteditable?: boolean
|
contenteditable?: boolean
|
||||||
contextmenu?: string
|
contextmenu?: string
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
import { isString } from '@vue/shared'
|
import { isString } from '@vue/shared'
|
||||||
|
|
||||||
export function patchStyle(el: any, prev: any, next: any) {
|
type Style = string | Partial<CSSStyleDeclaration> | null
|
||||||
const { style } = el
|
|
||||||
|
export function patchStyle(el: Element, prev: Style, next: Style) {
|
||||||
|
const style = (el as HTMLElement).style
|
||||||
if (!next) {
|
if (!next) {
|
||||||
el.removeAttribute('style')
|
el.removeAttribute('style')
|
||||||
} else if (isString(next)) {
|
} else if (isString(next)) {
|
||||||
style.cssText = next
|
style.cssText = next
|
||||||
} else {
|
} else {
|
||||||
for (const key in next) {
|
for (const key in next) {
|
||||||
style[key] = next[key]
|
style[key] = next[key] as string
|
||||||
}
|
}
|
||||||
if (prev && !isString(prev)) {
|
if (prev && !isString(prev)) {
|
||||||
for (const key in prev) {
|
for (const key in prev) {
|
||||||
|
@ -213,12 +213,12 @@ function debounce<T extends (...args: any[]) => any>(
|
|||||||
fn: T,
|
fn: T,
|
||||||
delay: number = 300
|
delay: number = 300
|
||||||
): T {
|
): T {
|
||||||
let prevTimer: NodeJS.Timeout | null = null
|
let prevTimer: number | null = null
|
||||||
return ((...args: any[]) => {
|
return ((...args: any[]) => {
|
||||||
if (prevTimer) {
|
if (prevTimer) {
|
||||||
clearTimeout(prevTimer)
|
clearTimeout(prevTimer)
|
||||||
}
|
}
|
||||||
prevTimer = setTimeout(() => {
|
prevTimer = window.setTimeout(() => {
|
||||||
fn(...args)
|
fn(...args)
|
||||||
prevTimer = null
|
prevTimer = null
|
||||||
}, delay)
|
}, delay)
|
||||||
|
Loading…
Reference in New Issue
Block a user