Skip to content

Instantly share code, notes, and snippets.

@ljmotta
Created October 14, 2020 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ljmotta/3fda742430705f869923c36201b6b770 to your computer and use it in GitHub Desktop.
Save ljmotta/3fda742430705f869923c36201b6b770 to your computer and use it in GitHub Desktop.
PingPongEnvelope
import { EnvelopeBus } from "@kogito-tooling/envelope-bus/dist/api";
import { Envelope } from "@kogito-tooling/envelope";
import { PingPongChannelApi, PingPongEnvelopeApi } from "../api";
// ...
export function init(args: { container: HTMLElement; bus: EnvelopeBus; pingPongViewFactory: PingPongFactory }) {
const envelope = new Envelope<
PingPongEnvelopeApi,
PingPongChannelApi,
PingPongEnvelopeViewApi,
PingPongEnvelopeContext
>(args.bus);
const envelopeViewDelegate = async () => {
const ref = React.createRef<PingPongEnvelopeViewApi>();
return new Promise<() => PingPongEnvelopeViewApi>((res) =>
ReactDOM.render(<PingPongEnvelopeView ref={ref} />, args.container, () => res(() => ref.current!))
);
};
const context: PingPongEnvelopeContext = {};
return envelope.start(envelopeViewDelegate, context, {
create: (apiFactoryArgs) => new PingPongEnvelopeApiImpl(apiFactoryArgs, args.pingPongViewFactory),
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment