aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/backends/static.js
blob: d2c8d3fe33d3ad045ca8adc5f43f78f2e16b2f8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * This backend uses the REST API only to host static instances,
 * without any Websocket connection.
 */
import { fetchApi } from "../utils"

export default class StaticBackend {
   constructor(store) {
       this.store = store
       this.onOpen()
   }

   onOpen() {
        this.fetchData("flows")
        // this.fetchData("events") # TODO: Add events log to static viewer.
   }

   fetchData(resource) {
       fetchApi(`./${resource}`)
           .then(res => res.json())
           .then(json => {
               this.receive(resource, json)
           })
   }

   receive(resource, data) {
       let type = `${resource}_RECEIVE`.toUpperCase()
       this.store.dispatch({ type, cmd: "receive", resource, data })
   }

}