Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
Prototype interfaces for Reactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-powwow committed Jul 25, 2024
1 parent 915caf1 commit d46bbd1
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions packages/reactor/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { EventEmitter } from 'events';

export interface Modification {
selector?: string;
xpath?: string;
Expand Down Expand Up @@ -25,10 +27,82 @@ export interface ModificationRequest {
modifications: Modification[];
}

export interface AppliedModification {
modificationRequest: ModificationRequest;
}

export interface DomJsonExportNode {
tag: string;
visible: boolean;
text?: string;
attributes?: Record<string, string>;
children?: DomJsonExportNode[];
}

interface ReactorEvents {
/**
* Called when a url is loaded by the browser. Can be used to modify the list
* of applied modifications.
* @param url the url that was loaded
*/
onUrlLoaded: (url: string) => void;

/**
* Called when a new page in an SPA is loaded by the browser. Can be used to
* modify the list of applied modifications.
* @param url the url that was loaded
* @param page the page that was loaded
*/
onPageLoaded: (url: string, page: string) => void;
}

/**
* Reactor applied modifications to the current page. Modifications
* are applied in the order they were added. Removing a modification
* unapplies it.
*/
interface Reactor extends EventEmitter {
/**
* Attach Reactor to the current tab. Reactor will start generating
* events and apply any modifications.
*/
attach(): void;

/**
* Detach Reactor from the current tab. Reactor will remove any applied
* modifications and stop generating events.
*/
detach(): void;

/**
* Get the list of currently applied modifications. This
* list is backed by the appliedModifications themselves, so
* make a change to the list will also apply/unapply any
* modifications as needed.
*
* @returns The list of applied modifications
*/
getAppliedModifications(): AppliedModification[];

/**
* Shortcut to add a modification. This is the equivalent of calling
* getAppliedModifications().push(modificationRequest)
*/
addModification(modificationRequest: ModificationRequest): void;

/**
* Shortcut to remove the most recently added modification. This
* is the equivalent of calling getAppliedModifications().pop()
*/
removeLastModification(): void;

/**
* Event listeners
*/
on: <K extends keyof ReactorEvents>(event: K, listener: ReactorEvents[K]) => this;

/**
* Event emitters
*/
emit: <K extends keyof ReactorEvents>(event: K, ...args: Parameters<ReactorEvents[K]>) => boolean;
}

0 comments on commit d46bbd1

Please sign in to comment.