[TMP 2] Plugins system. support directory structure and store system.(the plugin needs build at each project)
This commit is contained in:
@@ -1,22 +1,19 @@
|
||||
import React from "react";
|
||||
|
||||
import { initStore } from "./store/store";
|
||||
import { MainContainer } from "./main_container/MainContainer";
|
||||
|
||||
export const init = (plugin_context) => {
|
||||
const { useHook: useStore_CountPluginState } = plugin_context.createAtomWithHook({ count: 6 }, "CountPluginState");
|
||||
initStore(plugin_context.createAtomWithHook);
|
||||
|
||||
const EntryComponents = () => {
|
||||
|
||||
return (
|
||||
<MainContainer useStore_CountPluginState={useStore_CountPluginState}/>
|
||||
);
|
||||
|
||||
return <MainContainer />;
|
||||
};
|
||||
|
||||
// UI の"main_section"拡張ポイントにコンポーネントを登録
|
||||
plugin_context.registerComponent({
|
||||
plugin_id: "dev_vrct_plugin_example_1",
|
||||
plugin_id: "plugin_example_1_my_plugin",
|
||||
location: "main_section",
|
||||
component: EntryComponents,
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export default init;
|
||||
@@ -1,19 +1,18 @@
|
||||
import { useStore } from "../store/store";
|
||||
|
||||
export const MainContainer = () => {
|
||||
const { updateCountPluginState, currentCountPluginState } = useStore("useStore_CountPluginState");
|
||||
|
||||
export const MainContainer = ({useStore_CountPluginState}) => {
|
||||
const { updateCountPluginState, currentCountPluginState } = useStore_CountPluginState();
|
||||
const incrementCount = () => {
|
||||
updateCountPluginState((prev_value) => {
|
||||
return { count: prev_value.data.count + 1 }
|
||||
});
|
||||
updateCountPluginState((prev_value) => ({
|
||||
count: prev_value.data.count + 1,
|
||||
}));
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<p>Dev Plugin Count: {currentCountPluginState?.data?.count}</p>
|
||||
<button onClick={incrementCount}>
|
||||
Increment Plugin Count
|
||||
</button>
|
||||
<p>1 Zipped Dev Plugin Count: {currentCountPluginState?.data?.count}</p>
|
||||
<button onClick={incrementCount}>Increment Plugin Count</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
22
src-tauri/plugins/plugin_examples/store/store.js
Normal file
22
src-tauri/plugins/plugin_examples/store/store.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const store_hooks = {};
|
||||
|
||||
export const initStore = (createAtomWithHook) => {
|
||||
Object.assign(store_hooks, {
|
||||
useStore_CountPluginState: createAtomWithHook(
|
||||
{ count: 10 },
|
||||
"CountPluginState"
|
||||
).useHook,
|
||||
|
||||
useStore_AnotherState: createAtomWithHook(
|
||||
{ value: "initial" },
|
||||
"AnotherState"
|
||||
).useHook,
|
||||
});
|
||||
};
|
||||
|
||||
export const useStore = (hook_name) => {
|
||||
if (!store_hooks[hook_name]) {
|
||||
throw new Error(`Hook ${hook_name} is not initialized.`);
|
||||
}
|
||||
return store_hooks[hook_name]();
|
||||
};
|
||||
Reference in New Issue
Block a user