Skip to content

Commit

Permalink
feat: add validator run event to allow plugins to perform custom vali…
Browse files Browse the repository at this point in the history
…dation
  • Loading branch information
RebeccaStevens committed Feb 25, 2023
1 parent c565bc6 commit d97d3b8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/lib/application-events.ts
@@ -1,3 +1,4 @@
export const ApplicationEvents = {
BOOTSTRAP_END: "bootstrapEnd",
};
VALIDATION_RUN: "validationRun",
} as const;
8 changes: 8 additions & 0 deletions src/lib/application.ts
Expand Up @@ -107,6 +107,12 @@ export class Application extends ChildableComponent<
*/
static readonly EVENT_BOOTSTRAP_END = ApplicationEvents.BOOTSTRAP_END;

/**
* Emitted when validation is being run.
* The listener will be given an instance of {@link ProjectReflection}.
*/
static readonly EVENT_VALIDATION_RUN = ApplicationEvents.VALIDATION_RUN;

/**
* Create a new TypeDoc application instance.
*/
Expand Down Expand Up @@ -431,6 +437,8 @@ export class Application extends ChildableComponent<
validateLinks(project, this.logger);
}

this.trigger(Application.EVENT_VALIDATION_RUN, project);

this.logger.verbose(`Validation took ${Date.now() - start}ms`);
}

Expand Down
11 changes: 10 additions & 1 deletion src/lib/utils/events.ts
Expand Up @@ -7,6 +7,9 @@
// The Events object is a typesafe conversion of Backbones Events object:
// https://github.com/jashkenas/backbone/blob/05fde9e201f7e2137796663081105cd6dad12a98/backbone.js#L119-L374

import type { ProjectReflection } from "../models/index";
import type { Application } from "../application";

const uniqueId = (function () {
const prefixes: Record<string, number | undefined> = Object.create(null);
return function (prefix: string) {
Expand Down Expand Up @@ -433,6 +436,12 @@ export class EventDispatcher {
context?: any,
priority?: number
): this;
on(
name: (typeof Application)["EVENT_VALIDATION_RUN"],
callback?: (project: ProjectReflection) => void,
context?: any,
priority?: number
): this;
on(
name: string,
callback: EventCallback,
Expand All @@ -441,7 +450,7 @@ export class EventDispatcher {
): this;
on(
nameOrMap: EventMap | string,
callback: EventCallback,
callback: () => void,
context?: any,
priority?: number
) {
Expand Down

0 comments on commit d97d3b8

Please sign in to comment.