mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-17 20:51:55 +01:00
Replace lets with const where possible (#35)
This commit is contained in:
parent
97ca430884
commit
92dc82967c
@ -18,7 +18,7 @@ interface BlockProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const BlockHeader = ({ blockId, onClose }: BlockProps) => {
|
const BlockHeader = ({ blockId, onClose }: BlockProps) => {
|
||||||
const [blockData, blockDataLoading] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", blockId));
|
const [blockData] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", blockId));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key="header" className="block-header">
|
<div key="header" className="block-header">
|
||||||
|
@ -21,7 +21,7 @@ type WaveObjectValue<T extends WaveObj> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function splitORef(oref: string): [string, string] {
|
function splitORef(oref: string): [string, string] {
|
||||||
let parts = oref.split(":");
|
const parts = oref.split(":");
|
||||||
if (parts.length != 2) {
|
if (parts.length != 2) {
|
||||||
throw new Error("invalid oref");
|
throw new Error("invalid oref");
|
||||||
}
|
}
|
||||||
@ -54,11 +54,7 @@ function makeORef(otype: string, oid: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function GetObject<T>(oref: string): Promise<T> {
|
function GetObject<T>(oref: string): Promise<T> {
|
||||||
let prtn = $Call.ByName(
|
return $Call.ByName("github.com/wavetermdev/thenextwave/pkg/service/objectservice.ObjectService.GetObject", oref);
|
||||||
"github.com/wavetermdev/thenextwave/pkg/service/objectservice.ObjectService.GetObject",
|
|
||||||
oref
|
|
||||||
);
|
|
||||||
return prtn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const waveObjectValueCache = new Map<string, WaveObjectValue<any>>();
|
const waveObjectValueCache = new Map<string, WaveObjectValue<any>>();
|
||||||
@ -75,8 +71,8 @@ function createWaveValueObject<T extends WaveObj>(oref: string, shouldFetch: boo
|
|||||||
if (!shouldFetch) {
|
if (!shouldFetch) {
|
||||||
return wov;
|
return wov;
|
||||||
}
|
}
|
||||||
let startTs = Date.now();
|
const startTs = Date.now();
|
||||||
let localPromise = GetObject<T>(oref);
|
const localPromise = GetObject<T>(oref);
|
||||||
wov.pendingPromise = localPromise;
|
wov.pendingPromise = localPromise;
|
||||||
localPromise.then((val) => {
|
localPromise.then((val) => {
|
||||||
if (wov.pendingPromise != localPromise) {
|
if (wov.pendingPromise != localPromise) {
|
||||||
@ -138,24 +134,21 @@ function getWaveObjectAtom<T extends WaveObj>(oref: string): jotai.WritableAtom<
|
|||||||
waveObjectValueCache.set(oref, wov);
|
waveObjectValueCache.set(oref, wov);
|
||||||
}
|
}
|
||||||
return jotai.atom(
|
return jotai.atom(
|
||||||
(get) => {
|
(get) => get(wov.dataAtom).value,
|
||||||
let dataValue = get(wov.dataAtom);
|
|
||||||
return dataValue.value;
|
|
||||||
},
|
|
||||||
(_get, set, value: T) => {
|
(_get, set, value: T) => {
|
||||||
setObjectValue(value, set, true);
|
setObjectValue(value, set, true);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWaveObjectLoadingAtom<T extends WaveObj>(oref: string): jotai.Atom<boolean> {
|
function getWaveObjectLoadingAtom(oref: string): jotai.Atom<boolean> {
|
||||||
let wov = waveObjectValueCache.get(oref);
|
let wov = waveObjectValueCache.get(oref);
|
||||||
if (wov == null) {
|
if (wov == null) {
|
||||||
wov = createWaveValueObject(oref, true);
|
wov = createWaveValueObject(oref, true);
|
||||||
waveObjectValueCache.set(oref, wov);
|
waveObjectValueCache.set(oref, wov);
|
||||||
}
|
}
|
||||||
return jotai.atom((get) => {
|
return jotai.atom((get) => {
|
||||||
let dataValue = get(wov.dataAtom);
|
const dataValue = get(wov.dataAtom);
|
||||||
if (dataValue.loading) {
|
if (dataValue.loading) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -203,7 +196,7 @@ function updateWaveObject(update: WaveObjUpdate) {
|
|||||||
if (update == null) {
|
if (update == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let oref = makeORef(update.otype, update.oid);
|
const oref = makeORef(update.otype, update.oid);
|
||||||
let wov = waveObjectValueCache.get(oref);
|
let wov = waveObjectValueCache.get(oref);
|
||||||
if (wov == null) {
|
if (wov == null) {
|
||||||
wov = createWaveValueObject(oref, false);
|
wov = createWaveValueObject(oref, false);
|
||||||
@ -217,7 +210,7 @@ function updateWaveObject(update: WaveObjUpdate) {
|
|||||||
console.log("invalid wave object update", update);
|
console.log("invalid wave object update", update);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let curValue: WaveObjectDataItemType<WaveObj> = globalStore.get(wov.dataAtom);
|
const curValue: WaveObjectDataItemType<WaveObj> = globalStore.get(wov.dataAtom);
|
||||||
if (curValue.value != null && curValue.value.version >= update.obj.version) {
|
if (curValue.value != null && curValue.value.version >= update.obj.version) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -229,14 +222,14 @@ function updateWaveObject(update: WaveObjUpdate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateWaveObjects(vals: WaveObjUpdate[]) {
|
function updateWaveObjects(vals: WaveObjUpdate[]) {
|
||||||
for (let val of vals) {
|
for (const val of vals) {
|
||||||
updateWaveObject(val);
|
updateWaveObject(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanWaveObjectCache() {
|
function cleanWaveObjectCache() {
|
||||||
let now = Date.now();
|
const now = Date.now();
|
||||||
for (let [oref, wov] of waveObjectValueCache) {
|
for (const [oref, wov] of waveObjectValueCache) {
|
||||||
if (wov.refCount == 0 && wov.holdTime < now) {
|
if (wov.refCount == 0 && wov.holdTime < now) {
|
||||||
waveObjectValueCache.delete(oref);
|
waveObjectValueCache.delete(oref);
|
||||||
}
|
}
|
||||||
@ -280,11 +273,11 @@ function wrapObjectServiceCall<T>(fnName: string, ...args: any[]): Promise<T> {
|
|||||||
// should provide getFn if it is available (e.g. inside of a jotai atom)
|
// should provide getFn if it is available (e.g. inside of a jotai atom)
|
||||||
// otherwise it will use the globalStore.get function
|
// otherwise it will use the globalStore.get function
|
||||||
function getObjectValue<T>(oref: string, getFn?: jotai.Getter): T {
|
function getObjectValue<T>(oref: string, getFn?: jotai.Getter): T {
|
||||||
let wov = waveObjectValueCache.get(oref);
|
const wov = waveObjectValueCache.get(oref);
|
||||||
if (wov == null) {
|
if (wov === undefined) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (getFn == null) {
|
if (getFn === undefined) {
|
||||||
getFn = globalStore.get;
|
getFn = globalStore.get;
|
||||||
}
|
}
|
||||||
const atomVal = getFn(wov.dataAtom);
|
const atomVal = getFn(wov.dataAtom);
|
||||||
@ -296,11 +289,11 @@ function getObjectValue<T>(oref: string, getFn?: jotai.Getter): T {
|
|||||||
// otherwise it will use the globalStore.set function
|
// otherwise it will use the globalStore.set function
|
||||||
function setObjectValue<T extends WaveObj>(value: T, setFn?: jotai.Setter, pushToServer?: boolean) {
|
function setObjectValue<T extends WaveObj>(value: T, setFn?: jotai.Setter, pushToServer?: boolean) {
|
||||||
const oref = makeORef(value.otype, value.oid);
|
const oref = makeORef(value.otype, value.oid);
|
||||||
let wov = waveObjectValueCache.get(oref);
|
const wov = waveObjectValueCache.get(oref);
|
||||||
if (wov == null) {
|
if (wov === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (setFn == null) {
|
if (setFn === undefined) {
|
||||||
setFn = globalStore.set;
|
setFn = globalStore.set;
|
||||||
}
|
}
|
||||||
setFn(wov.dataAtom, { value: value, loading: false });
|
setFn(wov.dataAtom, { value: value, loading: false });
|
||||||
|
@ -61,11 +61,11 @@ function loadFiraCodeFont() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isFiraCodeLoaded = true;
|
isFiraCodeLoaded = true;
|
||||||
let firaCodeRegular = new FontFace("Fira Code", "url('/fonts/firacode-regular.woff2')", {
|
const firaCodeRegular = new FontFace("Fira Code", "url('/fonts/firacode-regular.woff2')", {
|
||||||
style: "normal",
|
style: "normal",
|
||||||
weight: "400",
|
weight: "400",
|
||||||
});
|
});
|
||||||
let firaCodeBold = new FontFace("Fira Code", "url('/fonts/firacode-bold.woff2')", {
|
const firaCodeBold = new FontFace("Fira Code", "url('/fonts/firacode-bold.woff2')", {
|
||||||
style: "normal",
|
style: "normal",
|
||||||
weight: "700",
|
weight: "700",
|
||||||
});
|
});
|
||||||
@ -80,19 +80,19 @@ function loadHackFont() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isHackFontLoaded = true;
|
isHackFontLoaded = true;
|
||||||
let hackRegular = new FontFace("Hack", "url('/fonts/hack-regular.woff2')", {
|
const hackRegular = new FontFace("Hack", "url('/fonts/hack-regular.woff2')", {
|
||||||
style: "normal",
|
style: "normal",
|
||||||
weight: "400",
|
weight: "400",
|
||||||
});
|
});
|
||||||
let hackBold = new FontFace("Hack", "url('/fonts/hack-bold.woff2')", {
|
const hackBold = new FontFace("Hack", "url('/fonts/hack-bold.woff2')", {
|
||||||
style: "normal",
|
style: "normal",
|
||||||
weight: "700",
|
weight: "700",
|
||||||
});
|
});
|
||||||
let hackItalic = new FontFace("Hack", "url('/fonts/hack-italic.woff2')", {
|
const hackItalic = new FontFace("Hack", "url('/fonts/hack-italic.woff2')", {
|
||||||
style: "italic",
|
style: "italic",
|
||||||
weight: "400",
|
weight: "400",
|
||||||
});
|
});
|
||||||
let hackBoldItalic = new FontFace("Hack", "url('/fonts/hack-bolditalic.woff2')", {
|
const hackBoldItalic = new FontFace("Hack", "url('/fonts/hack-bolditalic.woff2')", {
|
||||||
style: "italic",
|
style: "italic",
|
||||||
weight: "700",
|
weight: "700",
|
||||||
});
|
});
|
||||||
@ -111,7 +111,7 @@ function loadBaseFonts() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isBaseFontsLoaded = true;
|
isBaseFontsLoaded = true;
|
||||||
let mmFont = new FontFace("Martian Mono", "url(/fonts/MartianMono-VariableFont_wdth,wght.ttf)", {
|
const mmFont = new FontFace("Martian Mono", "url(/fonts/MartianMono-VariableFont_wdth,wght.ttf)", {
|
||||||
style: "normal",
|
style: "normal",
|
||||||
weight: "normal",
|
weight: "normal",
|
||||||
});
|
});
|
||||||
|
@ -13,7 +13,7 @@ function formatPath(path: PathType): string {
|
|||||||
return "$";
|
return "$";
|
||||||
}
|
}
|
||||||
let pathStr = "$";
|
let pathStr = "$";
|
||||||
for (let pathPart of path) {
|
for (const pathPart of path) {
|
||||||
if (typeof pathPart === "string") {
|
if (typeof pathPart === "string") {
|
||||||
if (simplePathStrRe.test(pathPart)) {
|
if (simplePathStrRe.test(pathPart)) {
|
||||||
pathStr += "." + pathPart;
|
pathStr += "." + pathPart;
|
||||||
@ -39,7 +39,7 @@ function isObject(obj: any): boolean {
|
|||||||
|
|
||||||
function getPath(obj: any, path: PathType): any {
|
function getPath(obj: any, path: PathType): any {
|
||||||
let cur = obj;
|
let cur = obj;
|
||||||
for (let pathPart of path) {
|
for (const pathPart of path) {
|
||||||
if (cur == null) {
|
if (cur == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ function checkPath(path: PathType): boolean {
|
|||||||
if (!isArray(path)) {
|
if (!isArray(path)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (let pathPart of path) {
|
for (const pathPart of path) {
|
||||||
if (typeof pathPart !== "string" && typeof pathPart !== "number") {
|
if (typeof pathPart !== "string" && typeof pathPart !== "number") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -118,7 +118,7 @@ function isEmpty(obj: any): boolean {
|
|||||||
return obj.length == 0;
|
return obj.length == 0;
|
||||||
}
|
}
|
||||||
if (isObject(obj)) {
|
if (isObject(obj)) {
|
||||||
for (let key in obj) {
|
for (const _ in obj) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -33,9 +33,9 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|||||||
await WOS.loadAndPinWaveObject<Client>(WOS.makeORef("client", clientId));
|
await WOS.loadAndPinWaveObject<Client>(WOS.makeORef("client", clientId));
|
||||||
const waveWindow = await WOS.loadAndPinWaveObject<WaveWindow>(WOS.makeORef("window", windowId));
|
const waveWindow = await WOS.loadAndPinWaveObject<WaveWindow>(WOS.makeORef("window", windowId));
|
||||||
await WOS.loadAndPinWaveObject<Workspace>(WOS.makeORef("workspace", waveWindow.workspaceid));
|
await WOS.loadAndPinWaveObject<Workspace>(WOS.makeORef("workspace", waveWindow.workspaceid));
|
||||||
let reactElem = React.createElement(App, null, null);
|
const reactElem = React.createElement(App, null, null);
|
||||||
let elem = document.getElementById("main");
|
const elem = document.getElementById("main");
|
||||||
let root = createRoot(elem);
|
const root = createRoot(elem);
|
||||||
document.fonts.ready.then(() => {
|
document.fonts.ready.then(() => {
|
||||||
console.log("Wave First Render");
|
console.log("Wave First Render");
|
||||||
root.render(reactElem);
|
root.render(reactElem);
|
||||||
|
Loading…
Reference in New Issue
Block a user