Skip to content

Commit

Permalink
lint: lib/realtime/realtime.ts
Browse files Browse the repository at this point in the history
- add ot typing

Signed-off-by: Raccoon <raccoon@hackmd.io>
  • Loading branch information
a60814billy committed Jun 16, 2021
1 parent 847acda commit f35d684
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/realtime/realtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface RealtimeNoteData {
updatetime: number

// type: ot.EditorSocketIOServer
server: any
server: ot.EditorSocketIOServer

authors: Record<string, RealtimeAuthorData>
authorship: Authorship[]
Expand Down Expand Up @@ -714,7 +714,7 @@ export function ifMayEdit(socket: SocketIO.Socket, callback: (canEdit: boolean)
}

// TODO: test it
function operationCallback(socket: SocketIO.Socket, operation: any) {
function operationCallback(socket: SocketIO.Socket, operation: ot.Operation[]) {
const noteId = socket.noteId
if (!noteId || !notes[noteId]) return
const note = notes[noteId]
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

"typeRoots": ["./typings", "./node_modules/@types"],
"paths": {
"@hackmd/diff-match-patch": ["./typings/diff-match-patch/"]
"@hackmd/diff-match-patch": ["./typings/diff-match-patch/"],
"ot": ["./typings/ot/"]
}
},
"include": [
Expand Down
62 changes: 62 additions & 0 deletions typings/ot/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import SocketIO from "socket.io";
import EventEmitter from "events";

declare module 'ot' {

export const version: number

export type Operation = number | string

export class TextOperation {
static isRetain(op: Operation): boolean

static isInsert(op: Operation): boolean

static isDelete(op: Operation): boolean
}

export class EditorSocketIOServer extends EventEmitter {

public isDirty: boolean
public document: string
public debug: boolean
public operations: Operation[]

constructor(
document: string,
operations: Operation[],
docId: string,
mayWrite: (
socket: SocketIO.Socket,
callback: (canEdit: boolean) => void) => void,
operationCallback: (
socket: SocketIO.Socket,
operation: Operation[]) => void,
operationEventCallback?: any)

setLogger(logger): void

debugLog(mes: string): void

setDocumentMaxLength(number): void

addClient(socket: SocketIO.Socket): void

onOperation(socket: SocketIO.Server, revision, operation, selection)

onGetOperations(socket, base, head)

updateSelection(socket, selection)

setName(socket, name)

setColor(socket, color)

getClient(clientId)

onDisconnect(socket)
}

}


0 comments on commit f35d684

Please sign in to comment.