mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +00:00
[web] Remove activeFetches and onMessage in StaticBackend.
This commit is contained in:
parent
dd43722c18
commit
32957976f5
@ -21,34 +21,16 @@ export default class StaticBackend {
|
||||
}
|
||||
|
||||
fetchData(resource) {
|
||||
let queue = []
|
||||
this.activeFetches[resource] = queue
|
||||
fetchApi(`/${resource}`)
|
||||
.then(res => res.json())
|
||||
.then(json => {
|
||||
if (this.activeFetches[resource] === queue)
|
||||
this.receive(resource, json)
|
||||
})
|
||||
}
|
||||
|
||||
onMessage(msg) {
|
||||
if (msg.cmd === CMD_RESET) {
|
||||
return this.fetchData(msg.resource)
|
||||
}
|
||||
if (msg.resource in this.activeFetches) {
|
||||
this.activeFetches[msg.resource].push(msg)
|
||||
} else {
|
||||
let type = `${msg.resource}_${msg.cmd}`.toUpperCase()
|
||||
this.store.dispatch({ type, ...msg})
|
||||
}
|
||||
}
|
||||
|
||||
receive(resource, data) {
|
||||
let type = `${resource}_RECEIVE`.toUpperCase()
|
||||
this.store.dispatch({ type, cmd: "receive", resource, data })
|
||||
let queue = this.activeFetches[resource]
|
||||
delete this.activeFetches[resource]
|
||||
queue.forEach(msg => this.onMessage(msg))
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user