aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/backends/static.js
blob: 1de6b29465d111d3f28f5c28dc55cca0afb3fa04 (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
32
33
34
35
36
/*
 * This backend uses the REST API only to host static instances,
 * without any Websocket connection.
 */
import { fetchApi } from "../utils"

const CMD_RESET = 'reset'

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

   onOpen() {
        this.fetchData("settings")
        this.fetchData("flows")
        this.fetchData("events")
        this.fetchData("options")
   }

   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 })
   }

}