Skip to content

Commit

Permalink
Restructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed Jan 13, 2022
1 parent e668bfd commit 31e77e4
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 40 deletions.
4 changes: 1 addition & 3 deletions discordium/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ export default createPlugin(config, ({Logger, Patcher, Styles, Data, Settings})
<div
className="example-clickable"
onClick={() => props.set({enabled: !props.enabled})}
>
Click to toggle
</div>
>Click to toggle</div>
</div>
);
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions discordium/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export {createLogger, Logger} from "./logger";
export {createPatcher, Patcher} from "./patcher";
export * as Finder from "./finder";
export {createStyles, Styles} from "./styles";
export {createData, Data} from "./data";
export {createSettings, Settings, SettingsProps} from "./settings";
export * as Discord from "./discord";
export {ReactInternals, ReactDOMInternals} from "./react";
File renamed without changes.
4 changes: 2 additions & 2 deletions discordium/patcher.ts → discordium/api/patcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Logger} from "./logger";
import {ContextMenuActions, ModalActions} from "./modules";
import {ContextMenuActions, ModalActions} from "../modules";

export interface Options {
silent?: boolean;
Expand Down Expand Up @@ -179,7 +179,7 @@ export const createPatcher = (id: string, Logger: Logger): Patcher => {
resolve(found);
} else {
// patch lazy load method
Logger.log(`Waiting for lazy load in "${method}" of "${resolveName(object, method)}"`);
Logger.log(`Waiting for lazy load in ${method} of ${resolveName(object, method)}`);
patcher.before(object, method, ({args, cancel}) => {
// replace resolver function
const original = args[arg];
Expand Down
2 changes: 1 addition & 1 deletion discordium/react.ts → discordium/api/react.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {React, ReactDOM} from "./modules";
import {React, ReactDOM} from "../modules";
import {Fiber} from "react-reconciler";

export {Fiber} from "react-reconciler";
Expand Down
4 changes: 2 additions & 2 deletions discordium/settings.ts → discordium/api/settings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Flux, Dispatch} from "./modules";
import {Flux, Dispatch} from "../modules";
import {Data} from "./data";
import {Event as DispatchEvent, Listener as DispatchListener} from "./modules/dispatch";
import {Event as DispatchEvent, Listener as DispatchListener} from "../modules/dispatch";

export type Listener<Data> = (data: Data) => void;

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions discordium/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./settings";
23 changes: 23 additions & 0 deletions discordium/components/settings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {React, classNames, Flex, Button, Form, margins} from "../modules";
import {confirm} from "../utils";

export interface SettingsContainerProps {
name: string;
children?: React.ReactNode;
onReset: () => void;
}

export const SettingsContainer = ({name, children, onReset}: SettingsContainerProps) => (
<Form.FormSection>
{children}
<Form.FormDivider className={classNames(margins.marginTop20, margins.marginBottom20)}/>
<Flex justify={Flex.Justify.END}>
<Button
size={Button.Sizes.SMALL}
onClick={() => confirm(name, "Reset all settings?", {
onConfirm: () => onReset()
})}
>Reset</Button>
</Flex>
</Form.FormSection>
);
45 changes: 19 additions & 26 deletions discordium/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import {confirm} from "./utils";
import {createLogger, Logger} from "./logger";
import {createPatcher, Patcher} from "./patcher";
import {createStyles, Styles} from "./styles";
import {createData, Data} from "./data";
import {createSettings, Settings, SettingsProps} from "./settings";
import {React, classNames, Flex, Button, Form, margins} from "./modules";
import {
createLogger,
Logger,
createPatcher,
Patcher,
createStyles,
Styles,
createData,
Data,
createSettings,
Settings,
SettingsProps
} from "./api";
import {React} from "./modules";
import {SettingsContainer} from "./components";

export {Finder, Discord, ReactInternals, ReactDOMInternals} from "./api";
export * as Utils from "./utils";
export * as Finder from "./finder";
export * as Modules from "./modules";
export {React, ReactDOM, classNames, lodash, Flux} from "./modules";
export {ReactInternals, ReactDOMInternals} from "./react";
export * as Discord from "./discord";
export {version} from "../package.json";

export {Logger} from "./logger";
export {Patcher} from "./patcher";
export {Styles} from "./styles";
export {Data} from "./data";
export {Settings, SettingsProps} from "./settings";
export {Logger, Patcher, Styles, Data, Settings, SettingsProps} from "./api";

export interface Api<
SettingsType extends Record<string, any>,
Expand Down Expand Up @@ -91,18 +93,9 @@ export const createPlugin = <
if (plugin.settingsPanel) {
const ConnectedSettings = Settings.connect(plugin.settingsPanel);
Wrapper.prototype.getSettingsPanel = () => (
<Form.FormSection>
<SettingsContainer name={name} onReset={() => Settings.reset()}>
<ConnectedSettings/>
<Form.FormDivider className={classNames(margins.marginTop20, margins.marginBottom20)}/>
<Flex justify={Flex.Justify.END}>
<Button
size={Button.Sizes.SMALL}
onClick={() => confirm(name, "Reset all settings?", {
onConfirm: () => Settings.reset()
})}
>Reset</Button>
</Flex>
</Form.FormSection>
</SettingsContainer>
);
}

Expand Down
3 changes: 2 additions & 1 deletion discordium/modules/dispatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Finder from "../finder";
import * as Finder from "../api/finder";

export interface Event extends Record<string, any> {
type: string;
Expand Down Expand Up @@ -32,4 +32,5 @@ export interface Module {
}

export const Dispatch: Module = Finder.query({props: ["default", "Dispatcher"], filter: (exports) => exports instanceof Object && !("ActionBase" in exports)});

export const Events: Dispatcher = Dispatch?.default;
2 changes: 1 addition & 1 deletion discordium/modules/flux.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Finder from "../finder";
import * as Finder from "../api/finder";
import {Dispatcher, Listener, Event, Token} from "./dispatch";

export declare class Store {
Expand Down
2 changes: 1 addition & 1 deletion discordium/modules/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import * as Finder from "../finder";
import * as Finder from "../api/finder";

export * from "./npm";
export {Dispatch, Events} from "./dispatch";
Expand Down
2 changes: 1 addition & 1 deletion discordium/modules/npm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Finder from "../finder";
import * as Finder from "../api/finder";

// we import instances for the typing
// FIXME: mirror versions!
Expand Down
2 changes: 1 addition & 1 deletion discordium/utils/react.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {React} from "../modules";
import {ReactDOMInternals, Fiber} from "../react";
import {ReactDOMInternals, Fiber} from "../api/react";

export type Predicate<Arg> = (arg: Arg) => boolean;

Expand Down
2 changes: 1 addition & 1 deletion tests/mock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Require} from "discordium/finder";
import {Require} from "discordium/api/finder";

global.TESTING = true;

Expand Down

0 comments on commit 31e77e4

Please sign in to comment.