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.
29 lines
657 B
29 lines
657 B
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
|
|
}
|
|
}
|
|
}
|
|
|