カスタム・イベントの公開
GlobalContext、RecordContextおよびBrowser-TabContextでUEFパブリッシュAPIを起動すると、任意のカスタム・イベントを公開できます。
公開APIが呼び出されるアクション名はCustomEventです。 パブリッシュ・リクエスト・ペイロードでは、setCustomEventName() APIおよびsetEventPayload() APIをそれぞれコールして、customEventNameおよびそのリクエストとともに任意のデータを渡すことができます。
この方法でcustomEventを公開すると、この同じイベントのサブスクリプションを以前に追加したすべてのレシーバに通知が呼び出されます。 また、これらのレシーバは、このパブリッシュ・リクエストが呼び出されるデータを取得します。
パブリッシュ・リクエストのレスポンス・オブジェクトでgetData()およびgetCustomEventName()をコールすると、パブリッシュ・リクエスト・フィードバックで渡される任意のデータを取得できます。
次の例は、様々なコンテキストでのカスタム・イベント公開リクエストの追加を示しています:
カスタム・イベントの公開(GlobalContext)
GlobalContext
にカスタム・イベント公開リクエストを追加するTypeScriptの例を次に示します。
const publishCustomEvent = async () => {
const payload: ICustomEventRequest = uiEventsFrameworkInstance.requestHelper.createPublishRequest('CustomEvent') as ICustomEventRequest;
payload.setCustomEventName('customEventName');
payload.setEventPayload({ message: 'any data' });
const globalContext: IGlobalContext = await uiEventsFrameworkInstance.getGlobalContext();
globalContext.publish(payload).then((message: IOperationResponse) => {
const response: ICustomEventResponse = message as ICustomEventResponse;
console.log(response.getResponseData());
console.log(response.getResponseData().getData());
console.log(response.getResponseData().getCustomEventName());
}).catch((err) => {
console.log(err);
});
};
GlobalContext
にカスタム・イベント公開リクエストを追加するJavaScriptの例を次に示します。
const publishCustomEvent = async () => {
const payload: ICustomEventRequest = uiEventsFrameworkInstance.requestHelper.createPublishRequest('CustomEvent') as ICustomEventRequest;
payload.setCustomEventName('customEventName');
payload.setEventPayload({ message: 'any data' });
const globalContext: IGlobalContext = await uiEventsFrameworkInstance.getGlobalContext();
globalContext.publish(payload).then((message: IOperationResponse) => {
const response: ICustomEventResponse = message as ICustomEventResponse;
console.log(response.getResponseData());
console.log(response.getResponseData().getData());
console.log(response.getResponseData().getCustomEventName());
}).catch((err) => {
console.log(err);
});
};
カスタム・イベントの公開(TabContext)
TabContext
にカスタム・イベント公開リクエストを追加するTypeScriptの例を次に示します。
const publishCustomEvent = async () => {
const payload: ICustomEventRequest = uiEventsFrameworkInstance.requestHelper.createPublishRequest('CustomEvent') as ICustomEventRequest;
payload.setCustomEventName('customEventName');
payload.setEventPayload({ message: 'any data' });
const tabContext: ITabContext = await uiEventsFrameworkInstance.getTabContext('browserTabId');
tabContext.publish(payload).then((message: IOperationResponse) => {
const response: ICustomEventResponse = message as ICustomEventResponse;
console.log(response.getResponseData());
console.log(response.getResponseData().getData());
console.log(response.getResponseData().getCustomEventName());
}).catch((err) => {
console.log(err);
});
};
TabContext
にカスタム・イベント公開リクエストを追加するJavaScriptの例を次に示します。
const publishCustomEvent = async () => {
const payload = uiEventsFrameworkInstance.requestHelper.createPublishRequest('CustomEvent');
payload.setCustomEventName('customEventName');
payload.setEventPayload({ message: 'any data' });
const tabContext = await uiEventsFrameworkInstance.getTabContext('browserTabId');
tabContext.publish(payload).then((message) => {
console.log(message.getResponseData());
console.log(message.getResponseData().getData());
console.log(message.getResponseData().getCustomEventName());
}).catch((err) => {
console.log(err);
});
};
カスタム・イベントの公開(RecordContext)
RecordContext
にカスタム・イベント公開リクエストを追加するTypeScriptの例を次に示します。
const subscribeCustomEvent = async () => {
const payload: ICustomEventSubscriptionRequest = uiEventsFrameworkInstance.requestHelper.createSubscriptionRequest('cxEventBusCustomEvent') as ICustomEventSubscriptionRequest;
payload.setCustomEventName('customEventName');
const tabContext: ITabContext = await uiEventsFrameworkInstance.getTabContext('browserTabId');
const recordContext: IRecordContext = await tabContext.getActiveRecord();
recordContext.subscribe(payload, (message: IEventResponse) => {
const response: ICustomEventSubscriptionResponse = message as ICustomEventSubscriptionResponse;
console.log(response.getResponseData());
console.log(response.getResponseData().getData());
console.log(response.getResponseData().getCustomEventName())
});
};
RecordContext
にカスタム・イベント公開リクエストを追加するJavaScriptの例を次に示します。
const publishCustomEvent = async () => {
const payload = uiEventsFrameworkInstance.requestHelper.createPublishRequest('CustomEvent');
payload.setCustomEventName('customEventName');
payload.setEventPayload({ message: 'any data' });
const tabContext = await uiEventsFrameworkInstance.getTabContext('browserTabId');
const recordContext: IRecordContext = await tabContext.getActiveRecord();
recordContext.publish(payload).then((message) => {
console.log(message.getResponseData());
console.log(message.getResponseData().getData());
console.log(message.getResponseData().getCustomEventName());
}).catch((err) => {
console.log(err);
});
};
これらのイベント・サブスクリプションおよび公開イベントを使用すると、UEFでサポートされていないレコードに新しいライフサイクル・イベントを定義できます。 特定のレコード・コンテキストのカスタム・イベント・サブスクリプションは、その特定のレコード・コンテキストでカスタム・イベント公開またはVBからのカスタム・イベント・トリガーが発生した場合にのみ通知を生成します。 その他のレコード・コンテキスト・サブスクリプションは通知されません。 同様に、特定のブラウザ・タブ・コンテキストのカスタム・イベント・サブスクリプションは、その特定のタブ・コンテキストでカスタム・イベント公開またはVBからのカスタム・イベント・トリガーが発生した場合にのみ通知を生成します。 他のタブ・コンテキスト・サブスクリプションは通知されません。
カスタム・イベントのこの機能により、UEFを介したVB内の外部アプリケーションから外部アプリケーションへの通信も可能になります。