@hocuspocus/server
Advanced tools
Comparing version 2.8.1 to 2.9.0-rc.0
@@ -8,3 +8,3 @@ import type { AbstractType, YArrayEvent } from 'yjs'; | ||
/** | ||
* A Hocuspocus Cloud App ID, get one here: https://collab.tiptap.dev | ||
* A Hocuspocus Cloud App ID, get one here: https://cloud.tiptap.dev | ||
*/ | ||
@@ -11,0 +11,0 @@ appId?: string; |
@@ -5,3 +5,3 @@ import { CompleteHocuspocusProviderWebsocketConfiguration, HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket.js'; | ||
/** | ||
* A Hocuspocus Cloud App ID, get one here: https://collab.tiptap.dev | ||
* A Hocuspocus Cloud App ID, get one here: https://cloud.tiptap.dev | ||
*/ | ||
@@ -8,0 +8,0 @@ appId: string; |
@@ -32,3 +32,7 @@ /// <reference types="node" /> | ||
debugger: Debugger; | ||
debounce: (id: string, func: Function, debounce: number, maxDebounce: number) => any; | ||
debouncer: { | ||
debounce: (id: string, func: Function, debounce: number, maxDebounce: number) => any; | ||
isDebounced: (id: string) => boolean; | ||
executeNow: (id: string) => any; | ||
}; | ||
constructor(configuration?: Partial<Configuration>); | ||
@@ -35,0 +39,0 @@ /** |
@@ -1,1 +0,5 @@ | ||
export declare const useDebounce: () => (id: string, func: Function, debounce: number, maxDebounce: number) => any; | ||
export declare const useDebounce: () => { | ||
debounce: (id: string, func: Function, debounce: number, maxDebounce: number) => any; | ||
isDebounced: (id: string) => boolean; | ||
executeNow: (id: string) => any; | ||
}; |
{ | ||
"name": "@hocuspocus/server", | ||
"description": "plug & play collaboration backend", | ||
"version": "2.8.1", | ||
"version": "2.9.0-rc.0", | ||
"homepage": "https://hocuspocus.dev", | ||
@@ -32,3 +32,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@hocuspocus/common": "^2.8.1", | ||
"@hocuspocus/common": "^2.9.0-rc.0", | ||
"async-lock": "^1.3.1", | ||
@@ -35,0 +35,0 @@ "kleur": "^4.1.4", |
@@ -80,3 +80,3 @@ import { IncomingMessage } from 'http' | ||
debounce = useDebounce() | ||
debouncer = useDebounce() | ||
@@ -356,15 +356,12 @@ constructor(configuration?: Partial<Configuration>) { | ||
// If it’s the last connection, we need to make sure to store the | ||
// document. Use the debounce helper, to clear running timers, | ||
// but make it run immediately if configured. | ||
// document. Use the debouncer executeNow helper, to run scheduled | ||
// onStoreDocument immediately and clear running timers. | ||
// If there is no scheduled run for this document there is no point in | ||
// triggering onStoreDocument hook, as everything seems to be stored already. | ||
// Only run this if the document has finished loading earlier (i.e. not to persist the empty | ||
// ydoc if the onLoadDocument hook returned an error) | ||
if (!document.isLoading) { | ||
this.debounce( | ||
`onStoreDocument-${document.name}`, | ||
() => { | ||
this.storeDocumentHooks(document, hookPayload) | ||
}, | ||
this.configuration.unloadImmediately ? 0 : this.configuration.debounce, | ||
this.configuration.maxDebounce, | ||
) | ||
if (!document.isLoading && this.debouncer.isDebounced(`onStoreDocument-${document.name}`)) { | ||
if (this.configuration.unloadImmediately) { | ||
this.debouncer.executeNow(`onStoreDocument-${document.name}`) | ||
} | ||
} else { | ||
@@ -410,7 +407,5 @@ // Remove document from memory immediately | ||
this.debounce( | ||
this.debouncer.debounce( | ||
`onStoreDocument-${document.name}`, | ||
() => { | ||
this.storeDocumentHooks(document, hookPayload) | ||
}, | ||
() => this.storeDocumentHooks(document, hookPayload), | ||
this.configuration.debounce, | ||
@@ -417,0 +412,0 @@ this.configuration.maxDebounce, |
export const useDebounce = () => { | ||
const timers: Map<string, { | ||
timeout: NodeJS.Timeout, | ||
start: number | ||
start: number, | ||
func: Function | ||
}> = new Map() | ||
@@ -36,6 +37,19 @@ | ||
timeout: setTimeout(run, debounce), | ||
func: run, | ||
}) | ||
} | ||
return debounce | ||
const executeNow = (id: string) => { | ||
const old = timers.get(id) | ||
if (old) { | ||
clearTimeout(old.timeout) | ||
return old.func() | ||
} | ||
} | ||
const isDebounced = (id: string): boolean => { | ||
return timers.has(id) | ||
} | ||
return { debounce, isDebounced, executeNow } | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
808150
9532
1