mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-02 19:49:58 +00:00
Adds a global API to notify devs / users of deprecated features.
- Custom callbacks may be added
- By default, remembers message text and only sends each message once
- Sends to console.warn by default
```ts
// Add a custom notification when a warning is encountered
const warnMessage = (message: string, source?: object) => {
addToast({ message, detail: object })
}
LiteGraph.onDeprecationWarning.push(warnMessage)
```
```ts
// Debugging flag. Repeats deprecation warnings every time they are reported.
// May impact performance.
LiteGraph.alwaysRepeatWarnings = true
```
Generate a warning
```ts
import { warnDeprecated } from "@/utils/feedback"
warnDeprecated(
"[DEPRECATED] graph.oldFeature() will be removed from Litegraph. " +
"Please use graph.newFeature() instead. https://helpful.site/faq",
objectThatCausedThis
)
```
28 lines
952 B
TypeScript
28 lines
952 B
TypeScript
import { LiteGraph } from "@/litegraph"
|
|
|
|
/** Guard against unbound allocation. */
|
|
const UNIQUE_MESSAGE_LIMIT = 10_000
|
|
const sentWarnings: Set<string> = new Set()
|
|
|
|
/**
|
|
* Warns that a deprecated function has been used via the public
|
|
* {@link onDeprecationWarning} / {@link onEveryDeprecationWarning} callback arrays.
|
|
* @param message Plain-language detail about what has been deprecated. This **should not** include unique data; use {@link source}.
|
|
* @param source A reference object to include alongside the message, e.g. `this`.
|
|
*/
|
|
export function warnDeprecated(message: string, source?: object): void {
|
|
if (!LiteGraph.alwaysRepeatWarnings) {
|
|
// Do not repeat
|
|
if (sentWarnings.has(message)) return
|
|
|
|
// Hard limit of unique messages per session
|
|
if (sentWarnings.size > UNIQUE_MESSAGE_LIMIT) return
|
|
|
|
sentWarnings.add(message)
|
|
}
|
|
|
|
for (const callback of LiteGraph.onDeprecationWarning) {
|
|
callback(message, source)
|
|
}
|
|
}
|