diff --git a/packages/shelter-docs/reference.md b/packages/shelter-docs/reference.md index 7ca1ed2..8b37b27 100644 --- a/packages/shelter-docs/reference.md +++ b/packages/shelter-docs/reference.md @@ -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 diff --git a/packages/shelter/src/flux.ts b/packages/shelter/src/flux.ts index 1b61a74..b653e18 100644 --- a/packages/shelter/src/flux.ts +++ b/packages/shelter/src/flux.ts @@ -1,4 +1,4 @@ -import { Dispatcher, FluxStore } from "./types"; +import { Dispatcher, FluxManager, FluxStore } from "./types"; import exfiltrate from "./exfiltrate"; declare global { @@ -34,6 +34,12 @@ exfiltrate("_dispatchToken", (store: FluxStore) => { return false; }); +export const managers: Array = []; +exfiltrate("initializedCount", (manager) => { + managers.push(manager); + return false; +}); + // I would make this pass `any` but IDE support is always nice! type Intercept = (payload: Record & { type: string }) => any; diff --git a/packages/shelter/src/types.ts b/packages/shelter/src/types.ts index 0a2cd31..ae84097 100644 --- a/packages/shelter/src/types.ts +++ b/packages/shelter/src/types.ts @@ -75,6 +75,18 @@ export type FluxStore> = T & { _reactChangeCallbacks: FluxStoreChangeCallbacks; }; +export type FluxManager = T & { + initializedCount: number; + actions: Record; + stores: Map; + + initialize: () => void; + terminate: (force: boolean) => void; + + _initialize: () => void; + _terminate: () => void; +}; + // TODO: Test if these are all correct. export interface HTTPRequest { url: string;