50 lines
806 B
JavaScript
50 lines
806 B
JavaScript
/**
|
|
* {}
|
|
* @author yutent<yutent.io@gmail.com>
|
|
* @date 2023/08/10 10:19:12
|
|
*/
|
|
|
|
import { Component } from 'wkit'
|
|
import { WKITD_COMPONENTS } from './constants.js'
|
|
|
|
class Wkitd extends WeakMap {
|
|
/**
|
|
* 广播式推送更新
|
|
*/
|
|
broadcast() {
|
|
for (let it of WKITD_COMPONENTS) {
|
|
if (it.removed) {
|
|
this.deassign(it)
|
|
continue
|
|
}
|
|
it.$requestUpdate()
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 注册缓存组件
|
|
*/
|
|
assign(target) {
|
|
WKITD_COMPONENTS.add(target)
|
|
}
|
|
|
|
/**
|
|
* 取消注册
|
|
*/
|
|
deassign(target) {
|
|
WKITD_COMPONENTS.delete(target)
|
|
}
|
|
}
|
|
|
|
const __WKITD__ = new Wkitd()
|
|
|
|
Object.defineProperty(window, 'wkitd', {
|
|
get() {
|
|
return __WKITD__
|
|
},
|
|
set(val) {
|
|
console.error('Can not set readonly property wkitd of window')
|
|
},
|
|
enumerable: false
|
|
})
|