From 8595053d28edbc36bb0507e1a867970570249b31 Mon Sep 17 00:00:00 2001 From: Richard Lewis Date: Mon, 4 Dec 2017 18:06:05 +0000 Subject: [PATCH] Update API data docs. --- src/WidgetMessaging.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/WidgetMessaging.js b/src/WidgetMessaging.js index 6703affc6a..7addbcae67 100644 --- a/src/WidgetMessaging.js +++ b/src/WidgetMessaging.js @@ -19,16 +19,18 @@ Listens for incoming postMessage requests from embedded widgets. The following A { api: "widget", action: "content_loaded", + widgetId: $WIDGET_ID, + data: {} // additional request fields - widgetId: $WIDGET_ID } The complete request object is returned to the caller with an additional "response" key like so: { api: "widget", action: "content_loaded", + widgetId: $WIDGET_ID, + data: {}, // additional request fields - widgetId: $WIDGET_ID response: { ... } } @@ -36,6 +38,8 @@ The "api" field is required to use this API, and must be set to "widget" in all The "action" determines the format of the request and response. All actions can return an error response. +Additional data can be sent as additional, abritrary fields. However, typically the data object should be used. + A success response is an object with zero or more keys. An error response is a "response" object which consists of a sole "error" key to indicate an error. @@ -209,6 +213,7 @@ function onMessage(event) { const action = event.data.action; const widgetId = event.data.widgetId; if (action === 'content_loaded') { + console.warn("Widget content loaded", widgetId); dis.dispatch({ action: 'widget_content_loaded', widgetId: widgetId,