feat(plugin): migrate plugin runner to rxjs

This commit is contained in:
austaras
2022-07-27 16:22:05 +08:00
parent 8280cf47b9
commit 21fbadb399
19 changed files with 323 additions and 431 deletions
@@ -3,30 +3,10 @@ import {
styled,
} from '@toeverything/components/ui';
import { Protocol } from '@toeverything/datasource/db-service';
import type {
AsyncBlock,
PluginHooks,
Virgo,
} from '@toeverything/framework/virgo';
import {
createContext,
useContext,
useEffect,
useState,
type CSSProperties,
} from 'react';
import type { AsyncBlock, Virgo } from '@toeverything/framework/virgo';
import { useEffect, useState, type CSSProperties } from 'react';
export type Store =
| {
editor: Virgo;
hooks: PluginHooks;
}
| Record<string, never>;
export const StoreContext = createContext<Store>({});
export const MenuApp = () => {
const { editor } = useContext(StoreContext);
export const MenuApp = ({ editor }: { editor: Virgo }) => {
const [show, setShow] = useState<boolean>(false);
const [style, setStyle] = useState<CSSProperties>();
const [selectedNodes, setSelectedNodes] = useState<AsyncBlock[]>([]);
@@ -1,7 +1,7 @@
import { StrictMode } from 'react';
import { BasePlugin } from '../../base-plugin';
import { PluginRenderRoot } from '../../utils';
import { MenuApp, StoreContext } from './MenuApp';
import { MenuApp } from './MenuApp';
const PLUGIN_NAME = 'selection-group';
@@ -10,27 +10,23 @@ export class SelectionGroupPlugin extends BasePlugin {
return PLUGIN_NAME;
}
private root: PluginRenderRoot | undefined;
private _root: PluginRenderRoot | undefined;
protected override _onRender() {
this.root = new PluginRenderRoot({
this._root = new PluginRenderRoot({
name: SelectionGroupPlugin.pluginName,
render: this.editor.reactRenderRoot?.render,
});
this.root.mount();
this.root.render(
this._root.mount();
this._root.render(
<StrictMode>
<StoreContext.Provider
value={{ editor: this.editor, hooks: this.hooks }}
>
<MenuApp />
</StoreContext.Provider>
<MenuApp editor={this.editor} />
</StrictMode>
);
}
public override dispose() {
this.root?.unmount();
this._root?.unmount();
super.dispose();
}
}