-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix(debug): remove component in beforeDestroy hook
* Use a set so components can only be in there once. * Debug data can be written even if syncService is undefined. Signed-off-by: Max <max@nextcloud.com> Signed-off-by: Max <max@nextcloud.com>
- Loading branch information
1 parent
4b9b174
commit 3aa227e
Showing
2 changed files
with
58 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
/** | ||
* Setup OCA.Text.debugYjs() and expose editor component in OCA.Text.editorComponents | ||
*/ | ||
|
||
if (!window.OCA.Text) { | ||
window.OCA.Text = {} | ||
} | ||
|
||
const editorComponents = window.OCA.Text.editorComponents ?? new Set() | ||
window.OCA.Text.editorComponents = editorComponents | ||
|
||
/** | ||
* Print debug info for all editor components as a warning. | ||
*/ | ||
export function debugYjs() { | ||
const intro = 'Editor Yjs debug data. Copy the objects above that start with "fileId".' | ||
const introChrome = '- In Chrome, select "Copy" at the end of the line.' | ||
const introFirefox = '- In Firefox, right-click on the object and select "Copy object".' | ||
const styleBold = 'font-weight: bold;' | ||
const styleItalic = 'font-weight: normal; font-style: italic;' | ||
|
||
for (const editorComponent of editorComponents.values()) { | ||
console.warn(JSON.stringify(editorComponent.debugData(), null, ' ')) | ||
} | ||
|
||
console.warn('%c%s\n%c%s\n%s', styleBold, intro, styleItalic, introChrome, introFirefox) | ||
} | ||
|
||
if (!window.OCA.Text.debugYjs) { | ||
window.OCA.Text.debugYjs = debugYjs | ||
} | ||
|
||
/** | ||
* Expose editor component in OCA.Text.editorComponents | ||
* @param {object} component - the editor component to include in debug output | ||
*/ | ||
export function exposeForDebugging(component) { | ||
editorComponents.add(component) | ||
} | ||
|
||
/** | ||
* Drop editor component from OCA.Text.editorComponents | ||
* @param {object} component - the editor component to remove from debug output | ||
*/ | ||
export function removeFromDebugging(component) { | ||
editorComponents.delete(component) | ||
} |