Registries

Nocto uses various registries to render UI.

Registry Concept

Nocto introduces concept of registries - they are singletons which are used to render UI. You might notice registries in your app under src/utils.ts (when using CLI).

import { SidebarRegistry, PluginConfigRegistry, RouteRegistry, NoctoConfig, SlotRegistry } from "@rsc-labs/noctojs-plugin-system"

export async function loadMyNoctoPlugins(noctoConfig: NoctoConfig) {

  SidebarRegistry.setConfig(noctoConfig.sidebar)

  const modules = {
    ...import.meta.glob("./plugins/**/index.ts", { eager: false }),
    ...import.meta.glob("./plugins/**/index.tsx", { eager: false }),
  }
  for (const path in modules) {
    const mod = await modules[path]() as any

    for (const key in mod) {
      const plugin = mod[key]
      if (noctoConfig.plugins[plugin.id] || noctoConfig.sidebar[plugin.id]) {
        let config = {}
        if (plugin.configSchema) {
          const userConfig = noctoConfig.plugins?.[plugin.id]?.config ?? {}
          PluginConfigRegistry.register(plugin.id, plugin.configSchema, userConfig)
        }

        if (typeof plugin.routes === "function") {
          const routes = plugin.routes(config)
          RouteRegistry.register(routes)
        }

        if (plugin.sidebar) {
          SidebarRegistry.register(plugin as unknown as any)
        }
        if (plugin.injections) {
          plugin.injections().forEach((c: any) => {
            if (SlotRegistry.get(c.pluginId, c.slot).length) {
              return;
            }
            SlotRegistry.register({ ...c })
          })
        }
        if (plugin.slots) {
          plugin.slots().forEach((c: any) => {
            if (SlotRegistry.get(plugin.id, c.slot).length) {
              return;
            }
            SlotRegistry.register({ pluginId: plugin.id, ...c })
          })
        }
      }
    }
  }
}

At this moment, they are used directly to register all your plugins, but it will be improved in the future. We have 4 kinds of registries.

Used for sidebar configuration. It contains list of plugins which will be rendered on the sidebar in predefined order.

Routes Registry

Used for registering the routes. This registry allows you to register totally new routes with new pages or override existing ones.

Plugin Config Registry

Used for storing plugin configuration. Every plugin can expose parameters which can be configurable via Nocto config. It let you then used your own parameters which will be passed directly to the plugin.

Slot Registry

Used for registering slots and injections. These concepts will be explained in details in the next sections, but in a brief - thanks to this registry you will be able to inject your UI elements into plugin.