MCPcopy
hub / github.com/editablejs/editable / constructor

Method constructor

packages/yjs-protocols/src/awareness.ts:47–86  ·  view source on GitHub ↗

* @param {Y.Doc} doc

(doc: Y.Doc)

Source from the content-addressed store, hash-verified

45 * @param {Y.Doc} doc
46 */
47 constructor(doc: Y.Doc) {
48 super()
49 this.doc = doc
50
51 this.clientID = doc.clientID
52 /**
53 * Maps from client id to client state
54 */
55 this.states = new Map()
56
57 this.meta = new Map()
58 this._checkInterval = setInterval(() => {
59 const now = time.getUnixTime()
60 if (
61 this.getLocalState() !== null &&
62 outdatedTimeout / 2 <= now - (this.meta.get(this.clientID)?.lastUpdated ?? 0)
63 ) {
64 // renew local clock
65 this.setLocalState(this.getLocalState())
66 }
67
68 const remove: number[] = []
69 this.meta.forEach((meta: { lastUpdated: number }, clientid: number) => {
70 if (
71 clientid !== this.clientID &&
72 outdatedTimeout <= now - meta.lastUpdated &&
73 this.states.has(clientid)
74 ) {
75 remove.push(clientid)
76 }
77 })
78 if (remove.length > 0) {
79 removeAwarenessStates(this, remove, 'timeout')
80 }
81 }, math.floor(outdatedTimeout / 10))
82 doc.on('destroy', () => {
83 this.destroy()
84 })
85 this.setLocalState({})
86 }
87
88 destroy() {
89 this.emit('destroy', [this])

Callers

nothing calls this directly

Calls 6

getLocalStateMethod · 0.95
setLocalStateMethod · 0.95
destroyMethod · 0.95
removeAwarenessStatesFunction · 0.85
getMethod · 0.80
onMethod · 0.80

Tested by

no test coverage detected