Last active
August 24, 2020 14:54
-
-
Save sylvanaar/c5aa6406bd4705def1006c298527edb6 to your computer and use it in GitHub Desktop.
modeling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const onlineState = { | |
states: { | |
idle: { | |
on: { | |
CONFIG_CHANGE: "fetching", | |
DATA_STALE: "fetching", | |
}, | |
}, | |
retrieving: {}, | |
fetching: { | |
// call the API, and populate the store | |
// "": [ | |
// { target: "idle", cond: "accessUnavailable" }, | |
// { target: "on", cond: "accessAvailable" }, | |
// ], | |
}, | |
dataRetrieved: { | |
// check that the new data is valid | |
// write it to the destination and go idle | |
// otherwise - perhaps follow some retry logic | |
}, | |
}, | |
}; | |
const dataPointManager = { | |
initial: "offline", | |
context: { | |
requestInfo: {}, | |
dataOutputKeyx = undefined, | |
dataExpiration: "datetime", | |
}, | |
states: { | |
online: { | |
on: { | |
OFFLINE: "offline", | |
}, | |
...onlineState, | |
}, | |
offline: { | |
on: { | |
ONLINE: "online", | |
}, | |
"": [{ target: "on", cond: "networkOnline" }], | |
}, | |
}, | |
}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const offlineStates = { | |
initial: "idle", | |
states: { | |
idle: { | |
on: { | |
NETCHANGE: "checking", | |
}, | |
}, | |
checking: { | |
"": [ | |
{ target: "idle", cond: "accessUnavailable" }, | |
{ target: "on", cond: "accessAvailable" }, | |
], | |
}, | |
}, | |
}; | |
const networkMachine = Machine({ | |
id: "network", | |
initial: "offline", | |
context: { | |
retries: 0, | |
}, | |
states: { | |
offline: { | |
on: { | |
NETUP: "online", | |
}, | |
...offlineStates, | |
}, | |
online: { | |
on: { | |
NETDOWN: "offline", | |
}, | |
}, | |
}, | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment