Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flux] exfiltrate managers #9

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/shelter-docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ While not likely, it *is possible* that a store you're trying to access has not

Therefore **it is strongly recommended** to rely on this function (instead of `flux.stores`/`flux.storesFlat`) if you need to access a store as soon as possible, immediately at plugin load.

### `shelter.flux.managers`

Managers are Discord's new way of handling side effects in Flux. They are lazily loaded through a dispatch interceptor.

This contains a list of all managers.

### `shelter.flux.intercept`

```ts
Expand Down
8 changes: 7 additions & 1 deletion packages/shelter/src/flux.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dispatcher, FluxStore } from "./types";
import { Dispatcher, FluxManager, FluxStore } from "./types";
import exfiltrate from "./exfiltrate";

declare global {
Expand Down Expand Up @@ -34,6 +34,12 @@ exfiltrate("_dispatchToken", (store: FluxStore) => {
return false;
});

export const managers: Array<FluxManager> = [];
exfiltrate("initializedCount", (manager) => {
managers.push(manager);
return false;
});

// I would make this pass `any` but IDE support is always nice!
type Intercept = (payload: Record<string, any> & { type: string }) => any;

Expand Down
12 changes: 12 additions & 0 deletions packages/shelter/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ export type FluxStore<T = Record<string, any>> = T & {
_reactChangeCallbacks: FluxStoreChangeCallbacks;
};

export type FluxManager<T = unknown> = T & {
initializedCount: number;
actions: Record<string, Function>;
stores: Map<FluxStore, Function>;

initialize: () => void;
terminate: (force: boolean) => void;

_initialize: () => void;
_terminate: () => void;
};

// TODO: Test if these are all correct.
export interface HTTPRequest {
url: string;
Expand Down