refactor(api/react): rename stuff
This commit is contained in:
parent
122c3a11e9
commit
dc81e9cfad
5 changed files with 16 additions and 11 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { addJSXCallback } from "@lib/api/jsx";
|
||||
import { onJsxCreate } from "@lib/api/react/jsx";
|
||||
import { after } from "@lib/api/patcher";
|
||||
import { findByName } from "@metro";
|
||||
import { useEffect, useState } from "react";
|
||||
|
|
@ -24,7 +24,7 @@ export default defineCorePlugin({
|
|||
const propHolder = {} as Record<string, any>;
|
||||
const badgeCache = {} as Record<string, BunnyBadge[]>;
|
||||
|
||||
addJSXCallback("RenderedBadge", (_, ret) => {
|
||||
onJsxCreate("RenderedBadge", (_, ret) => {
|
||||
if (ret.props.id.match(/bunny-\d+-\d+/)) {
|
||||
Object.assign(ret.props, propHolder[ret.props.id]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { VdPluginManager } from "@core/vendetta/plugins";
|
|||
import { patchCommands } from "@lib/api/commands";
|
||||
import { patchLogHook } from "@lib/api/debug";
|
||||
import { injectFluxInterceptor } from "@lib/api/flux";
|
||||
import { patchJSX } from "@lib/api/jsx";
|
||||
import { patchJsx } from "@lib/api/react/jsx";
|
||||
import { removeFile, writeFile } from "@lib/api/native/fs";
|
||||
import { isPyonLoader, isThemeSupported } from "@lib/api/native/loader";
|
||||
import { FileManager } from "@lib/api/native/modules";
|
||||
|
|
@ -43,7 +43,7 @@ export default async () => {
|
|||
patchLogHook(),
|
||||
patchCommands(),
|
||||
patchChatBackground(),
|
||||
patchJSX(),
|
||||
patchJsx(),
|
||||
initVendettaObject(),
|
||||
initFetchI18nStrings(),
|
||||
initSettings(),
|
||||
|
|
|
|||
|
|
@ -6,3 +6,4 @@ export * as native from "./native";
|
|||
export * as patcher from "./patcher";
|
||||
export * as settings from "./settings";
|
||||
export * as storage from "./storage";
|
||||
export * as react from "./react";
|
||||
|
|
|
|||
1
src/lib/api/react/index.ts
Normal file
1
src/lib/api/react/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * as jsx from "./jsx";
|
||||
|
|
@ -1,17 +1,17 @@
|
|||
import { after } from "@lib/api/patcher";
|
||||
import { findByPropsLazy } from "@metro";
|
||||
|
||||
type Callback = (Component: any, ret: JSX.Element) => void;
|
||||
type Callback = (Component: any, ret: JSX.Element) => JSX.Element;
|
||||
const callbacks = new Map<string, Callback[]>();
|
||||
|
||||
const jsxRuntime = findByPropsLazy("jsx", "jsxs");
|
||||
|
||||
export function addJSXCallback(Component: string, callback: Callback) {
|
||||
export function onJsxCreate(Component: string, callback: Callback) {
|
||||
if (!callbacks.has(Component)) callbacks.set(Component, []);
|
||||
callbacks.get(Component)!.push(callback);
|
||||
}
|
||||
|
||||
export function removeJSXCallback(Component: string, callback: Callback) {
|
||||
export function deleteJsxCreate(Component: string, callback: Callback) {
|
||||
if (!callbacks.has(Component)) return;
|
||||
const cbs = callbacks.get(Component)!;
|
||||
cbs.splice(cbs.indexOf(callback), 1);
|
||||
|
|
@ -21,12 +21,15 @@ export function removeJSXCallback(Component: string, callback: Callback) {
|
|||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function patchJSX() {
|
||||
// Only a simple name check for now
|
||||
const callback = ([Component, props]: any[], ret: any) => {
|
||||
export function patchJsx() {
|
||||
const callback = ([Component]: unknown[], ret: JSX.Element) => {
|
||||
// The check could be more complex, but this is fine for now to avoid overhead
|
||||
if (typeof Component === "function" && callbacks.has(Component.name)) {
|
||||
const cbs = callbacks.get(Component.name)!;
|
||||
for (const cb of cbs) ret = cb(Component, ret);
|
||||
for (const cb of cbs) {
|
||||
const _ret = cb(Component, ret);
|
||||
if (_ret !== undefined) ret = _ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue