format: run prettify

This commit is contained in:
SethBurkart123
2025-05-05 18:04:10 +10:00
parent 771169348f
commit 0f9f618164
142 changed files with 28768 additions and 20790 deletions
+32 -24
View File
@@ -3,20 +3,26 @@ class ReactFiber {
private debug: boolean;
private messageIdCounter: number = 0; // Counter for unique message IDs
constructor(selector: string, options: {
debug ? : boolean
} = {}) {
constructor(
selector: string,
options: {
debug?: boolean;
} = {},
) {
this.selector = selector;
this.debug = options.debug || false;
}
static find(selector: string, options: {
debug ? : boolean
} = {}) {
static find(
selector: string,
options: {
debug?: boolean;
} = {},
) {
return new ReactFiber(selector, options);
}
private async sendMessage(action: string, payload: any = {}): Promise < any > {
private async sendMessage(action: string, payload: any = {}): Promise<any> {
return new Promise((resolve, _) => {
const messageId = this.messageIdCounter++;
const message = {
@@ -29,56 +35,58 @@ class ReactFiber {
};
const listener = (response: any) => {
if (response.data?.type === 'reactFiberResponse' && response.data?.messageId === messageId) {
if (
response.data?.type === "reactFiberResponse" &&
response.data?.messageId === messageId
) {
if (this.debug) {
console.log("Content Received Response:", response.data.response);
}
resolve(response.data.response);
window.removeEventListener("message", listener)
window.removeEventListener("message", listener);
}
};
window.addEventListener('message', listener);
window.addEventListener("message", listener);
window.postMessage(message, "*");
});
}
async getState(key ? : string | string[]): Promise < any > {
async getState(key?: string | string[]): Promise<any> {
return this.sendMessage("getState", {
key
key,
});
}
async setState(update: any | ((prevState: any) => any)): Promise < ReactFiber > {
const updateFnString = typeof update === 'function' ? update.toString() : null;
const updateObject = typeof update !== 'function' ? update : null;
async setState(update: any | ((prevState: any) => any)): Promise<ReactFiber> {
const updateFnString =
typeof update === "function" ? update.toString() : null;
const updateObject = typeof update !== "function" ? update : null;
await this.sendMessage("setState", {
updateFn: updateFnString,
updateObject
updateObject,
});
return this;
}
async getProps(propName ? : string): Promise < any > {
async getProps(propName?: string): Promise<any> {
return this.sendMessage("getProp", {
propName
propName,
});
}
async setProp(propName: string, value: any): Promise < ReactFiber > {
async setProp(propName: string, value: any): Promise<ReactFiber> {
await this.sendMessage("setProp", {
propName,
value
value,
});
return this;
}
async forceUpdate(): Promise < ReactFiber > {
async forceUpdate(): Promise<ReactFiber> {
await this.sendMessage("forceUpdate");
return this;
}
}
export default ReactFiber;
export default ReactFiber;