Skip to content

Commit

Permalink
Further testing
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Jan 23, 2024
1 parent 7c9be9a commit 13368f9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
9 changes: 7 additions & 2 deletions frontend/src/framework/Module.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";

import { Atom } from "jotai";
import { cloneDeep } from "lodash";

import { BroadcastChannelsDef, InputBroadcastChannelDef } from "./Broadcaster";
Expand Down Expand Up @@ -46,6 +47,7 @@ export class Module<StateType extends StateBaseType> {
private _drawPreviewFunc: DrawPreviewFunc | null;
private _description: string | null;
private _inputChannelDefs: InputBroadcastChannelDef[];
private _atoms: Atom<any>[];

constructor(
name: string,
Expand All @@ -54,7 +56,8 @@ export class Module<StateType extends StateBaseType> {
broadcastChannelsDef: BroadcastChannelsDef = {},
inputChannelDefs: InputBroadcastChannelDef[] = [],
drawPreviewFunc: DrawPreviewFunc | null = null,
description: string | null = null
description: string | null = null,
atoms: Atom<any>[] = []
) {
this._name = name;
this._defaultTitle = defaultTitle;
Expand All @@ -69,6 +72,7 @@ export class Module<StateType extends StateBaseType> {
this._inputChannelDefs = inputChannelDefs;
this._drawPreviewFunc = drawPreviewFunc;
this._description = description;
this._atoms = atoms;
}

getDrawPreviewFunc(): DrawPreviewFunc | null {
Expand Down Expand Up @@ -123,7 +127,8 @@ export class Module<StateType extends StateBaseType> {
instanceNumber,
this._channelsDef,
this._workbench,
this._inputChannelDefs
this._inputChannelDefs,
this._atoms
);
this._moduleInstances.push(instance);
this.maybeImportSelf();
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/framework/ModuleInstance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ErrorInfo } from "react";

import { createStore } from "jotai";
import { Atom, createStore } from "jotai";
import { cloneDeep } from "lodash";

import { BroadcastChannel, BroadcastChannelsDef, InputBroadcastChannelDef } from "./Broadcaster";
Expand Down Expand Up @@ -45,13 +45,15 @@ export class ModuleInstance<StateType extends StateBaseType> {
private _workbench: Workbench;

private _jotaiStore: ReturnType<typeof createStore> = createStore();
private _jotaiAtoms: Atom<unknown>[] = [];

constructor(
module: Module<StateType>,
instanceNumber: number,
broadcastChannelsDef: BroadcastChannelsDef,
workbench: Workbench,
inputChannelDefs: InputBroadcastChannelDef[]
inputChannelDefs: InputBroadcastChannelDef[],
atoms: Atom<unknown>[]
) {
this._id = `${module.getName()}-${instanceNumber}`;
this._title = module.getDefaultTitle();
Expand Down Expand Up @@ -92,6 +94,8 @@ export class ModuleInstance<StateType extends StateBaseType> {
);
});
}

this._jotaiAtoms = atoms;
}

getJotaiStore(): ReturnType<typeof createStore> {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/framework/ModuleRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Atom } from "jotai";

import { BroadcastChannelsDef, InputBroadcastChannelDef } from "./Broadcaster";
import { Module } from "./Module";
import { DrawPreviewFunc } from "./Preview";
Expand All @@ -13,6 +15,7 @@ export type RegisterModuleOptions = {
inputChannelDefs?: InputBroadcastChannelDef[];
preview?: DrawPreviewFunc;
description?: string;
atoms?: Atom<unknown>[];
};

export class ModuleNotFoundError extends Error {
Expand Down Expand Up @@ -42,7 +45,8 @@ export class ModuleRegistry {
options.broadcastChannelsDef,
options.inputChannelDefs,
options.preview ?? null,
options.description ?? null
options.description ?? null,
options.atoms ?? []
);
this._registeredModules[options.moduleName] = module;
return module;
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/modules/MyModule2/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export const vectorsAtom = atomWithQuery((get) => ({
),
}));
export const atomBasedOnVectors = atom<boolean>((get) => get(vectorsAtom).isFetching);

export const atoms = [selectedEnsembleAtom, vectorsAtom, atomBasedOnVectors];
3 changes: 2 additions & 1 deletion frontend/src/modules/MyModule2/registerModule.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ModuleRegistry } from "@framework/ModuleRegistry";

import { atoms } from "./atoms";
import { State } from "./state";

ModuleRegistry.registerModule<State>({ moduleName: "MyModule2", defaultTitle: "My Module 2" });
ModuleRegistry.registerModule<State>({ moduleName: "MyModule2", defaultTitle: "My Module 2", atoms: atoms });

0 comments on commit 13368f9

Please sign in to comment.