Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ralismark committed Jan 13, 2024
1 parent 3887247 commit 9570994
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
34 changes: 18 additions & 16 deletions src/backend/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { setMerging } from "../codemirror/merge"
import { stateFromJSON, stateToJSON, trFromJSON, trToJSON } from "../codemirror/share"
import { toast } from "react-toastify"

// TODO when we close a file before it's put, it's not actually put

export const NumDirty = new ExternState<number>(0)
export const NumSyncing = new ExternState<number>(0)

Expand Down Expand Up @@ -126,7 +128,7 @@ export class File {

this.bc.onmessage = ev => {
const msg: Msg = ev.data
console.log("[file]", this.path, this.id, "recv", msg)
console.debug("[file]", this.path, this.id, "recv", msg)
if (msg.type === "requestState") {
const reply: MsgState = {
type: "state",
Expand All @@ -135,7 +137,7 @@ export class File {
baseETag: this.baseETag,
remoteETag: this.remoteETag,
}
console.log("[file]", this.path, this.id, "send", reply)
console.debug("[file]", this.path, this.id, "send", reply)
bc.postMessage(reply)
} else if (msg.type === "state") {
// do nothing
Expand All @@ -160,13 +162,13 @@ export class File {
}

const unsub = this.esr.subscribe(tr => {
console.log("[file]", this.path, this.id, "tr", tr)
console.debug("[file]", this.path, this.id, "tr", tr)
if (!tr.annotation(Transaction.remote)) {
const msg: MsgUpdate = {
type: "update",
tr: trToJSON(tr),
}
console.log("[file]", path, "send", msg)
console.debug("[file]", path, this.id, "send", msg)
this.bc.postMessage(msg)
}

Expand All @@ -182,20 +184,20 @@ export class File {
const close = () => {
bc.close()
unsub()
console.log("[file]", this.path, this.id, "close")
console.debug("[file]", this.path, this.id, "close")
}
if (this.abort.signal.aborted) close()
else this.abort.signal.addEventListener("abort", close)

console.log("[file]", this.path, this.id, "construct", this)
console.debug("[file]", this.path, this.id, "construct", this)
}

/**
* new wraps the constructor, handling the logic for loading the file from
* another instance, or localstorage/store.
*/
static async new(store: Store, path: string): Promise<File> {
console.log("[file]", path, "new")
console.debug("[file]", path, "new")
const bc = new BroadcastChannel(`ibis/file/${path}`)

type Ret = { state: EditorState, lastSaved: Text, baseETag: ETag, remoteETag: ETag }
Expand All @@ -205,7 +207,7 @@ export class File {
// try getting the state from another instance
bc.onmessage = ev => {
const msg: Msg = ev.data
console.log("[file]", path, "recv", msg)
console.debug("[file]", path, "recv", msg)
if (msg.type === "state") {
done.abort()
bc.onmessage = null
Expand All @@ -218,7 +220,7 @@ export class File {
}
}
const msg: MsgRequestState = { type: "requestState" }
console.log("[file]", path, "send", msg)
console.debug("[file]", path, "send", msg)
bc.postMessage(msg)

await sleep(STATE_REPLY_TIMEOUT_MS)
Expand Down Expand Up @@ -267,7 +269,7 @@ export class File {
baseETag: out.baseETag,
remoteETag: out.remoteETag,
}
console.log("[file]", path, "send", msg)
console.debug("[file]", path, "send", msg)
bc.postMessage(msg)

bc.onmessage = null
Expand Down Expand Up @@ -343,11 +345,11 @@ export class File {
tr: trToJSON(tr),
remoteETag: etag,
}
console.log("[file]", this.path, this.id, "send", msg)
console.debug("[file]", this.path, this.id, "send", msg)
this.bc.postMessage(msg)

toast.warn(`Conflicting changes on "${this.path}", please fix manually`)
console.log("[file]", this.path, this.id, "conflict", this.remoteETag, this.baseETag)
console.debug("[file]", this.path, this.id, "conflict", this.remoteETag, this.baseETag)
} else {
toast.error(`Couldn't save "${this.path}": ${e}`)
}
Expand All @@ -365,7 +367,7 @@ export class File {
baseETag: this.baseETag,
remoteETag: this.remoteETag,
}
console.log("[file]", this.path, this.id, "send", msg)
console.debug("[file]", this.path, this.id, "send", msg)
this.bc.postMessage(msg)
})
}
Expand Down Expand Up @@ -403,7 +405,7 @@ export class File {
tr: trToJSON(tr),
baseETag: this.baseETag,
}
console.log("[file]", this.path, this.id, "send", msg)
console.debug("[file]", this.path, this.id, "send", msg)
this.bc.postMessage(msg)
}

Expand All @@ -417,12 +419,12 @@ export class File {
content: this.doc().toString(),
etag: this.baseETag,
}
console.log("[file]", this.path, this.id, "stash", stashed)
console.debug("[file]", this.path, this.id, "stash", stashed)
LsWal.setItem(this.path, JSON.stringify(stashed))
}

private clearStash() {
console.log("[file]", this.path, this.id, "clearStash")
console.debug("[file]", this.path, this.id, "clearStash")
LsWal.removeItem(this.path)
}
}
2 changes: 1 addition & 1 deletion src/components/IbisSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function IbisSearch() {
else if (e.code === "ArrowUp") setSelected(getNextPrev()[0])
else if (e.code === "ArrowDown") setSelected(getNextPrev()[1])
else if (e.code === "Enter") accept()
else console.log(e.code)
//else console.log(e.code)
}}
autoComplete="off"
placeholder="Search"
Expand Down
2 changes: 1 addition & 1 deletion src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function batched<T>(
let activeTask: Promise<void> | null = null

const startProcess = async () => {
while (pending) {
while (pending.length > 0) {
const batch = pending
pending = []
const p = process(batch)
Expand Down

0 comments on commit 9570994

Please sign in to comment.