wkitd/src/init.js

50 lines
806 B
JavaScript
Raw Normal View History

2023-08-10 19:59:02 +08:00
/**
* {}
* @author yutent<yutent.io@gmail.com>
* @date 2023/08/10 10:19:12
*/
import { Component } from 'wkit'
import { WKITD_COMPONENTS } from './constants.js'
2023-08-10 19:59:02 +08:00
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', {
2023-08-14 22:20:16 +08:00
get() {
return __WKITD__
},
set(val) {
console.error('Can not set readonly property wkitd of window')
2023-08-14 22:20:16 +08:00
},
enumerable: false
})