forked from vuejs/core
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuseCEStyleAttrs.ts
More file actions
32 lines (29 loc) · 890 Bytes
/
useCEStyleAttrs.ts
File metadata and controls
32 lines (29 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { getCurrentInstance, warn, watchPostEffect } from '@vue/runtime-core'
export function useCEStyleAttrs(
getter: (ctx: any) => Array<Record<string, string | number>>
) {
if (!__BROWSER__ && !__TEST__) return
const instance = getCurrentInstance()
/* istanbul ignore next */
if (!instance) {
__DEV__ &&
warn(
`useCEStyleAttrs is called without current active component instance.`
)
return
}
instance.hasStyleAttrs = true
let oAttrs: undefined | Array<Record<string, string | number>> = undefined
const setAttrs = () => {
const attrs = getter(instance.proxy)
if (instance.ceContext) {
if (instance.isCE) {
instance.ceContext.setStyleAttrs('root', attrs, oAttrs)
} else {
instance.ceContext.setStyleAttrs(instance.uid, attrs, oAttrs)
}
oAttrs = attrs
}
}
watchPostEffect(setAttrs)
}