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.
38 lines
855 B
38 lines
855 B
import EventChannel from './EventChannel'
|
|
|
|
const eventChannels = {}
|
|
|
|
const eventChannelStack = []
|
|
|
|
let id = 0
|
|
|
|
export function initEventChannel (events, cache = true) {
|
|
id++
|
|
const eventChannel = new EventChannel(id, events)
|
|
if (cache) {
|
|
eventChannels[id] = eventChannel
|
|
eventChannelStack.push(eventChannel)
|
|
}
|
|
return eventChannel
|
|
}
|
|
|
|
export function getEventChannel (id) {
|
|
if (id) {
|
|
const eventChannel = eventChannels[id]
|
|
delete eventChannels[id]
|
|
return eventChannel
|
|
}
|
|
return eventChannelStack.shift()
|
|
}
|
|
|
|
export default {
|
|
args (fromArgs, toArgs) {
|
|
const id = initEventChannel(fromArgs.events).id
|
|
if (fromArgs.url) {
|
|
fromArgs.url = fromArgs.url + (fromArgs.url.indexOf('?') === -1 ? '?' : '&') + '__id__=' + id
|
|
}
|
|
},
|
|
returnValue (fromRes, toRes) {
|
|
fromRes.eventChannel = getEventChannel()
|
|
}
|
|
}
|
|
|