diff options
| author | Maximilian Hils <git@maximilianhils.com> | 2017-04-30 15:23:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-04-30 15:23:20 +0200 |
| commit | fccc9bc45ef55e3e7f14ee4a51f376c53b418991 (patch) | |
| tree | a29c33256f8361d5e332ad874afede02e8b0b061 /web/src/js/ducks/connection.js | |
| parent | 29ce5a83d2b4cec067731c2f2f77e1cda134c866 (diff) | |
| parent | 97a00728a85a32ca6a8e98a991f6dcf28809e73b (diff) | |
| download | mitmproxy-fccc9bc45ef55e3e7f14ee4a51f376c53b418991.tar.gz mitmproxy-fccc9bc45ef55e3e7f14ee4a51f376c53b418991.tar.bz2 mitmproxy-fccc9bc45ef55e3e7f14ee4a51f376c53b418991.zip | |
Merge pull request #2271 from mhils/mitmweb-connection-indicator
[web] add connection indicator [WIP]
Diffstat (limited to 'web/src/js/ducks/connection.js')
| -rw-r--r-- | web/src/js/ducks/connection.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/web/src/js/ducks/connection.js b/web/src/js/ducks/connection.js new file mode 100644 index 00000000..ffa2c309 --- /dev/null +++ b/web/src/js/ducks/connection.js @@ -0,0 +1,44 @@ +export const ConnectionState = { + INIT: Symbol("init"), + FETCHING: Symbol("fetching"), // WebSocket is established, but still startFetching resources. + ESTABLISHED: Symbol("established"), + ERROR: Symbol("error"), + OFFLINE: Symbol("offline"), // indicates that there is no live (websocket) backend. +} + +const defaultState = { + state: ConnectionState.INIT, + message: null, +} + +export default function reducer(state = defaultState, action) { + switch (action.type) { + + case ConnectionState.ESTABLISHED: + case ConnectionState.FETCHING: + case ConnectionState.ERROR: + case ConnectionState.OFFLINE: + return { + state: action.type, + message: action.message + } + + default: + return state + } +} + +export function startFetching() { + return { type: ConnectionState.FETCHING } +} + +export function connectionEstablished() { + return { type: ConnectionState.ESTABLISHED } +} + +export function connectionError(message) { + return { type: ConnectionState.ERROR, message } +} +export function setOffline() { + return { type: ConnectionState.OFFLINE } +} |
