0.0.100 • Published 5 months ago

stitch-sdk-ali v0.0.100

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

stitch-sdk

Usage

yarn:

yarn add stitch-sdk

npm:

npm install stitch-sdk

Integrate Stitch's app/module into existing app page

  1. Publish your app/module in Stitch.
  2. Set the app/module's access privilege as public.
  3. Add code in your existing app as below.

Import style

import "stitch-sdk/dist/style.css";

For react app:

import { StitchAppView } from "stitch-sdk";

<StitchAppView appId="{YOUR_APPLICATION_ID}" />;

StitchViewProps

NameTypeDescriptionDefault value
appIdstringThe app's id in Stitch. Required!--
baseUrlstringStitch's api base urlhttps://api.openblocks.dev
onModuleEventTriggered(eventName: string) => voidTriggered when module's custom event is triggered. Works only when the app is a module.--
onModuleOutputChange(output: any) => voidTriggered when module's outputs change. Works only when the app is a module.--

Invoke module methods

import { useRef } from "ref";
import { StitchAppView } from "stitch-sdk";

function MyExistingAppPage() {
  const appRef = useRef();
  return (
    <div>
      <StitchAppView appId={YOUR_APPLICATION_ID} ref={appRef} />;
      <button onClick={() => appRef.current?.invokeMethod("some-method-name")}>
        Invoke method
      </button>
    </div>
  );
}

For vanilla js:

import { bootstrapAppAt } from "stitch-sdk";

const node = document.querySelector("#my-app");

async function bootstrap() {
  const instance = await bootstrapAppAt(YOUR_APPLICATION_ID, node);

  // set module inputs
  instance.setModuleInputs({ input1: "xxx", input2: "xxx" });

  // invoke module methods
  instance.setModuleInputs({ input1: "xxx", input2: "xxx" });

  // listen module event trigger
  instance.on("moduleEventTriggered", (eventName) => {
    console.info("event triggered:", eventName);
  });

  // listen module output change
  instance.on("moduleOutputChange", (data) => {
    console.info("output data:", data);
  });
}
0.0.100

5 months ago

0.0.11

5 months ago

0.0.10

6 months ago

0.0.6

6 months ago

0.0.5

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago