openblocks-sdk
Usage
yarn:
yarn add openblocks-sdk
npm:
npm install openblocks-sdk
Integrate Openblocks' app/module into existing app page
- Publish your app/module in Openblocks.
- Set the app/module's access privilege as public.
- Add code in your existing app as below.
Import style
import "openblocks-sdk/dist/style.css";
For react app:
import { OpenblocksAppView } from "openblocks-sdk";
<OpenblocksAppView appId="{YOUR_APPLICATION_ID}" />;
OpenblocksViewProps
Name | Type | Description | Default value |
---|
appId | string | The app's id in Openblocks. Required! | -- |
baseUrl | string | Openblocks' api base url | https://api.openblocks.dev |
onModuleEventTriggered | (eventName: string) => void | Triggered when module's custom event is triggered. Works only when the app is a module. | -- |
onModuleOutputChange | (output: any) => void | Triggered when module's outputs change. Works only when the app is a module. | -- |
Invoke module methods
import { useRef } from "ref";
import { OpenblocksAppView } from "openblocks-sdk";
function MyExistingAppPage() {
const appRef = useRef();
return (
<div>
<OpenblocksAppView appId={YOUR_APPLICATION_ID} ref={appRef} />;
<button onClick={() => appRef.current?.invokeMethod("some-method-name")}>
Invoke method
</button>
</div>
);
}
For vanilla js:
import { bootstrapAppAt } from "openblocks-sdk";
const node = document.querySelector("#my-app");
async function bootstrap() {
const instance = await bootstrapAppAt(YOUR_APPLICATION_ID, node);
instance.setModuleInputs({ input1: "xxx", input2: "xxx" });
instance.setModuleInputs({ input1: "xxx", input2: "xxx" });
instance.on("moduleEventTriggered", (eventName) => {
console.info("event triggered:", eventName);
});
instance.on("moduleOutputChange", (data) => {
console.info("output data:", data);
});
}