智能照明系统APP-本地串口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LightingSystemApp-serial/.svn/pristine/0f/0f492927b4abeb741b0d0c86ec2...

37 lines
895 B

3 years ago
import {
publish
} from '../bridge'
const callbacks = {}
const WEB_INVOKE_APPSERVICE = 'WEB_INVOKE_APPSERVICE'
// 简单处理 view 层与 service 层的通知系统
/**
* 消费 view 层通知
*/
export function consumePlusMessage (type, args) {
// 处理 web-view 组件发送的通知
if (type === WEB_INVOKE_APPSERVICE) {
publish(WEB_INVOKE_APPSERVICE, args.data, args.webviewIds)
return true
}
const callback = callbacks[type]
if (callback) {
callback(args)
if (!callback.keepAlive) {
delete callbacks[type]
}
return true
}
return false
}
/**
* 注册 view 层通知 service 层事件处理
*/
export function registerPlusMessage (type, callback, keepAlive = true) {
if (callbacks[type]) {
return console.warn(`${type} 已注册:` + (callbacks[type].toString()))
}
callback.keepAlive = !!keepAlive
callbacks[type] = callback
}