mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 15:14:52 +09:00
Process updates of the resource EventSubscriber are subscribed to and have it keep a mapping of id to value syncronised with event provider as long as there are subscription callbacks registered with it. The mapping is kept around after the last callback is unsubscribed so that it can be efficiently resynced with the resource based on the updatedAt timestaps of individual elements. This allows the EventSubscriber to provide the right building blocks to provide its values to React components via the the useSyncExternalStore hook. This in turn greatly simplifies the web_ui models for the subscribed resources.
29 lines
880 B
TypeScript
29 lines
880 B
TypeScript
import React, { useContext } from "react";
|
|
|
|
import * as lib from "@clusterio/lib";
|
|
|
|
import ControlContext from "./ControlContext";
|
|
import BaseWebPlugin from "../BaseWebPlugin";
|
|
|
|
|
|
type PluginExtraProps = {
|
|
component: string;
|
|
instance?: lib.InstanceDetails;
|
|
user?: lib.User;
|
|
host?: lib.HostDetails;
|
|
role?: lib.Role;
|
|
};
|
|
export default function PluginExtra(props: PluginExtraProps) {
|
|
let control = useContext(ControlContext);
|
|
|
|
let components = [];
|
|
for (let [name, plugin] of control.plugins) {
|
|
if (Object.prototype.hasOwnProperty.call(plugin.componentExtra, props.component)) {
|
|
type ComponentExtra = {[key: string]: React.ComponentType<PluginExtraProps & {plugin:BaseWebPlugin}>};
|
|
let ComponentExtra = (plugin.componentExtra as ComponentExtra)[props.component];
|
|
components.push(<ComponentExtra key={name} plugin={plugin} {...props}/>);
|
|
}
|
|
}
|
|
return components;
|
|
}
|