-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #189 from pkova/master
landscape: complain if vere is out of date
- Loading branch information
Showing
3 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import api from '@/api'; | ||
import create, { SetState } from 'zustand'; | ||
import produce from 'immer'; | ||
|
||
interface Vere { | ||
cur: VereState; | ||
next?: VereState; | ||
set: SetState<Vere>; | ||
loaded: boolean; | ||
isLatest: boolean; | ||
vereVersion: string; | ||
latestVereVersion: string; | ||
} | ||
|
||
interface VereState { | ||
rev: string; | ||
non?: string; | ||
zuse?: number; | ||
arvo?: number; | ||
lull?: number; | ||
hoon?: number; | ||
nock?: number; | ||
} | ||
|
||
const useVereState = create<Vere>((set, get) => ({ | ||
loaded: false, | ||
set | ||
})) | ||
|
||
const fetchRuntimeVersion = () => { | ||
api.thread({ | ||
inputMark: 'noun', | ||
outputMark: 'vere-update', | ||
desk: 'base', | ||
threadName: 'runtime-version', | ||
body: '', | ||
}).then((data: Vere) => { | ||
useVereState.setState((state) => { | ||
const vereVersion = data.cur.rev.split('/vere/~.')[1]; | ||
const isLatest = data.next === undefined; | ||
const latestVereVersion = !isLatest ? data.next.rev.split('/vere/~.')[1] : vereVersion | ||
return Object.assign(data, {loaded: true, isLatest, vereVersion, latestVereVersion}); | ||
}) | ||
}); | ||
} | ||
|
||
fetchRuntimeVersion() | ||
|
||
setInterval(fetchRuntimeVersion, 1800000) | ||
|
||
export default useVereState;; | ||
|
||
// window.vere = useVereState.getState; |