aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/backends/static.js
blob: 6657fecf1ee295f8072fbd73ddb9ec2bb6cfac2d (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
/*
 * 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("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 })
   }

}