智能照明系统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/7f/7fe6e6469ade0312583b377b9d4...

30 lines
657 B

3 years ago
const callbacks = {}
export default function createCallbacks (namespace) {
let scopedCallbacks = callbacks[namespace]
if (!scopedCallbacks) {
scopedCallbacks = {
id: 1,
callbacks: Object.create(null)
}
callbacks[namespace] = scopedCallbacks
}
return {
get (id) {
return scopedCallbacks.callbacks[id]
},
pop (id) {
const callback = scopedCallbacks.callbacks[id]
if (callback) {
delete scopedCallbacks.callbacks[id]
}
return callback
},
push (callback) {
const id = scopedCallbacks.id++
scopedCallbacks.callbacks[id] = callback
return id
}
}
}