npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ibm-wch-sdk-api

v5.0.361

Published

Exposes framework independent APIs for ibm-wch-sdk-ng and similar SDKs.

Downloads

27

Readme

ibm-wch-sdk-api

Exposes framework independent APIs for ibm-wch-sdk-ng and similar SDKs.

Details

Refer to the documentation.

Changes

CHANGELOG

Class documentation

Refer to the documentation.

Usage

Install the module via

npm install --save ibm-wch-sdk-theme

API

Changelog

Current

Changed

Added

  • New quick access fields group and groups on the RenderingContext
  • Typing support for group elements
  • Declaration of the event types and payloads for cross iframe events to switch between public and protected mode.

5.0.217

Added

  • Initial version

ibm-wch-sdk-api

Index

External modules


Services

  • [logging][./logging/]
  • [info][./info/]

Interfaces

External module: "index"

Index


ibm-wch-sdk-api > "interfaces/delivery/v1/base.item"

External module: "interfaces/delivery/v1/base.item"

Index

Enumerations

Interfaces


ibm-wch-sdk-api > "interfaces/delivery/v1/content/content.item"

External module: "interfaces/delivery/v1/content/content.item"

Index

Interfaces


ibm-wch-sdk-api > "interfaces/delivery/v1/content/elements"

External module: "interfaces/delivery/v1/content/elements"

Index

Type aliases

Variables


Type aliases

ELEMENT_TYPE

Ƭ ELEMENT_TYPE: * "text" | "number" | "toggle" | "formattedtext" | "link" | "datetime" | "file" | "video" | "image" | "reference" | "category" | "location" | "optionselection" | "group" *

Defined in interfaces/delivery/v1/content/elements.ts:2


Variables

<Const> _ELEMENT_TYPE_CATEGORY

● _ELEMENT_TYPE_CATEGORY: "category" = "category"

Defined in interfaces/delivery/v1/content/elements.ts:14


<Const> _ELEMENT_TYPE_DATE

● _ELEMENT_TYPE_DATE: "datetime" = "datetime"

Defined in interfaces/delivery/v1/content/elements.ts:13


<Const> _ELEMENT_TYPE_FILE

● _ELEMENT_TYPE_FILE: "file" = "file"

Defined in interfaces/delivery/v1/content/elements.ts:15


<Const> _ELEMENT_TYPE_FORMATTED_TEXT

● _ELEMENT_TYPE_FORMATTED_TEXT: "formattedtext" = "formattedtext"

Defined in interfaces/delivery/v1/content/elements.ts:9


<Const> _ELEMENT_TYPE_GROUP

● _ELEMENT_TYPE_GROUP: "group" = "group"

Defined in interfaces/delivery/v1/content/elements.ts:6


<Const> _ELEMENT_TYPE_IMAGE

● _ELEMENT_TYPE_IMAGE: "image" = "image"

Defined in interfaces/delivery/v1/content/elements.ts:17


<Const> _ELEMENT_TYPE_LINK

● _ELEMENT_TYPE_LINK: "link" = "link"

Defined in interfaces/delivery/v1/content/elements.ts:12


<Const> _ELEMENT_TYPE_LOCATION

● _ELEMENT_TYPE_LOCATION: "location" = "location"

Defined in interfaces/delivery/v1/content/elements.ts:19


<Const> _ELEMENT_TYPE_NUMBER

● _ELEMENT_TYPE_NUMBER: "number" = "number"

Defined in interfaces/delivery/v1/content/elements.ts:10


<Const> _ELEMENT_TYPE_OPTION_SELECTION

● _ELEMENT_TYPE_OPTION_SELECTION: "optionselection" = "optionselection"

Defined in interfaces/delivery/v1/content/elements.ts:7


<Const> _ELEMENT_TYPE_REFERENCE

● _ELEMENT_TYPE_REFERENCE: "reference" = "reference"

Defined in interfaces/delivery/v1/content/elements.ts:18


<Const> _ELEMENT_TYPE_TEXT

● _ELEMENT_TYPE_TEXT: "text" = "text"

Defined in interfaces/delivery/v1/content/elements.ts:8


<Const> _ELEMENT_TYPE_TOGGLE

● _ELEMENT_TYPE_TOGGLE: "toggle" = "toggle"

Defined in interfaces/delivery/v1/content/elements.ts:11


<Const> _ELEMENT_TYPE_VIDEO

● _ELEMENT_TYPE_VIDEO: "video" = "video"

Defined in interfaces/delivery/v1/content/elements.ts:16


ibm-wch-sdk-api > "interfaces/delivery/v1/error/error"

External module: "interfaces/delivery/v1/error/error"

Index

Interfaces


ibm-wch-sdk-api > "interfaces/delivery/v1/layout/layout"

External module: "interfaces/delivery/v1/layout/layout"

Index

Interfaces


ibm-wch-sdk-api > "interfaces/delivery/v1/rendering/context/content.item.with.layout"

External module: "interfaces/delivery/v1/rendering/context/content.item.with.layout"

Index

Interfaces


ibm-wch-sdk-api > "interfaces/delivery/v1/rendering/context/extended.context"

External module: "interfaces/delivery/v1/rendering/context/extended.context"

Index

Interfaces


ibm-wch-sdk-api > "interfaces/delivery/v1/rendering/context/hub.context"

External module: "interfaces/delivery/v1/rendering/context/hub.context"

Index

Interfaces


ibm-wch-sdk-api > "interfaces/delivery/v1/rendering/context/rendering.context"

External module: "interfaces/delivery/v1/rendering/context/rendering.context"

Index

Interfaces

Type aliases


Type aliases

Element

Ƭ Element: * LocationElement | SingleReferenceElement | MultiReferenceElement | SingleImageElement | MultiImageElement | SingleVideoElement | MultiVideoElement | SingleFileElement | MultiFileElement | SingleToggleElement | MultiToggleElement | SingleTextElement | MultiTextElement | SingleNumberElement | MultiNumberElement | SingleLinkElement | MultiLinkElement | SingleFormattedTextElement | MultiFormattedTextElement | SingleOptionSelectionElement | MultiOptionSelectionElement | SingleDateElement | MultiDateElement | SingleGroupElement | MultiGroupElement *

Defined in interfaces/delivery/v1/rendering/context/rendering.context.ts:386


GroupType

Ƭ GroupType: ElementMap<SimpleType>

Defined in interfaces/delivery/v1/rendering/context/rendering.context.ts:402


SimpleType

Ƭ SimpleType: * string | string[] | number | number[] | Image | Image[] | Date | Date[] | Video | Video[] | File | File[] | boolean | boolean[] | Link | Link[] | OptionSelection | OptionSelection[] | RenderingContext | RenderingContext[] | Category | Location | object *

Defined in interfaces/delivery/v1/rendering/context/rendering.context.ts:398


ibm-wch-sdk-api > "interfaces/delivery/v1/search/search.result"

External module: "interfaces/delivery/v1/search/search.result"

Index

Interfaces


ibm-wch-sdk-api > "interfaces/delivery/v1/site/site"

External module: "interfaces/delivery/v1/site/site"

Index

Interfaces


ibm-wch-sdk-api > "interfaces/delivery/v1/site/site.child"

External module: "interfaces/delivery/v1/site/site.child"

Index

Interfaces


ibm-wch-sdk-api > "interfaces/delivery/v1/site/site.context"

External module: "interfaces/delivery/v1/site/site.context"

Index

Interfaces


ibm-wch-sdk-api > "interfaces/delivery/v1/site/site.page"

External module: "interfaces/delivery/v1/site/site.page"

Index

Interfaces


ibm-wch-sdk-api > "interfaces/delivery/v1/user/user"

External module: "interfaces/delivery/v1/user/user"

Index

Interfaces


ibm-wch-sdk-api > "interfaces/delivery/v1/users/currentuser/constants"

External module: "interfaces/delivery/v1/users/currentuser/constants"

Index

Variables


Variables

<Const> REL_PATH_CURRENT_USER

● REL_PATH_CURRENT_USER: "user-profile/v1/users/currentuser" = "user-profile/v1/users/currentuser"

Defined in interfaces/delivery/v1/users/currentuser/constants.ts:2


ibm-wch-sdk-api > "interfaces/logging/logger"

External module: "interfaces/logging/logger"

Index

Interfaces


ibm-wch-sdk-api > "interfaces/logging/logger.factory"

External module: "interfaces/logging/logger.factory"

Index

Interfaces


ibm-wch-sdk-api > "interfaces/login/v1/basicauth/index"

External module: "interfaces/login/v1/basicauth/index"

Index

Variables


Variables

<Const> HEADER_BASICAUTH_TENANT_ID

● HEADER_BASICAUTH_TENANT_ID: "x-ibm-dx-tenant-id" = "x-ibm-dx-tenant-id"

Defined in interfaces/login/v1/basicauth/index.ts:6


<Const> KEY_BASICAUTH_LOGIN_PASSWORD

● KEY_BASICAUTH_LOGIN_PASSWORD: "j_password" = "j_password"

Defined in interfaces/login/v1/basicauth/index.ts:4


<Const> KEY_BASICAUTH_LOGIN_USERNAME

● KEY_BASICAUTH_LOGIN_USERNAME: "j_username" = "j_username"

Defined in interfaces/login/v1/basicauth/index.ts:3


<Const> REL_PATH_BASICAUTH_LOGIN

● REL_PATH_BASICAUTH_LOGIN: "login/v1/basicauth" = "login/v1/basicauth"

Defined in interfaces/login/v1/basicauth/index.ts:2


ibm-wch-sdk-api > "interfaces/login/v1/redirect/index"

External module: "interfaces/login/v1/redirect/index"

Index

Variables


Variables

<Const> PARAM_REDIRECT_LOGIN_TARGET_TENANT

● PARAM_REDIRECT_LOGIN_TARGET_TENANT: "targetTenant" = "targetTenant"

Defined in interfaces/login/v1/redirect/index.ts:3


<Const> PARAM_REDIRECT_LOGIN_TARGET_URL

● PARAM_REDIRECT_LOGIN_TARGET_URL: "targetUrl" = "targetUrl"

Defined in interfaces/login/v1/redirect/index.ts:2


<Const> REL_PATH_REDIRECT_LOGIN

● REL_PATH_REDIRECT_LOGIN: "login/v1/redirect" = "login/v1/redirect"

Defined in interfaces/login/v1/redirect/index.ts:1


ibm-wch-sdk-api > "interfaces/login/v1/removecookies/index"

External module: "interfaces/login/v1/removecookies/index"

Index

Variables


Variables

<Const> REL_PATH_REMOVECOOKIES

● REL_PATH_REMOVECOOKIES: "login/v1/removecookies" = "login/v1/removecookies"

Defined in interfaces/login/v1/removecookies/index.ts:2


ibm-wch-sdk-api > "interfaces/messages/messages"

External module: "interfaces/messages/messages"

Index

Interfaces

Type aliases


Type aliases

SdkMessageHandlerCallback

Ƭ SdkMessageHandlerCallback: function

Defined in interfaces/messages/messages.ts:21

Type declaration

▸(aPayload: SdkMessagePayload, aEvent: MessageEvent): PromiseLike<SdkMessagePayload> | SdkMessagePayload | null | undefined

Parameters:

| Param | Type | | ------ | ------ | | aPayload | SdkMessagePayload | | aEvent | MessageEvent |

Returns: PromiseLike<SdkMessagePayload> | SdkMessagePayload | null | undefined


ibm-wch-sdk-api > "interfaces/messages/sdk.navigate.by.path.message"

External module: "interfaces/messages/sdk.navigate.by.path.message"

Index

Interfaces

Variables


Variables

<Const> SDK_NAVIGATE_BY_PATH_EVENT_TYPE

● SDK_NAVIGATE_BY_PATH_EVENT_TYPE: "WchSdk.router.navigateByPath" = "WchSdk.router.navigateByPath"

Defined in interfaces/messages/sdk.navigate.by.path.message.ts:7


ibm-wch-sdk-api > "interfaces/messages/sdk.refresh.message"

External module: "interfaces/messages/sdk.refresh.message"

Index

Interfaces

Variables


Variables

<Const> SDK_REFRESH_EVENT_TYPE

● SDK_REFRESH_EVENT_TYPE: "WchSdk.refresh" = "WchSdk.refresh"

Defined in interfaces/messages/sdk.refresh.message.ts:7


ibm-wch-sdk-api > "interfaces/messages/sdk.set.mode.message"

External module: "interfaces/messages/sdk.set.mode.message"

Index

Interfaces

Variables


Variables

<Const> SDK_SET_MODE_EVENT_TYPE

● SDK_SET_MODE_EVENT_TYPE: "WchSdk.setMode" = "WchSdk.setMode"

Defined in interfaces/messages/sdk.set.mode.message.ts:8


ibm-wch-sdk-api > "interfaces/messages/sdk.subscribe.active.route.message"

External module: "interfaces/messages/sdk.subscribe.active.route.message"

Index

Interfaces

Variables


Variables

<Const> SDK_ACTIVE_ROUTE_EVENT_TYPE

● SDK_ACTIVE_ROUTE_EVENT_TYPE: "WchSdk.router.activeRoute" = "WchSdk.router.activeRoute"

Defined in interfaces/messages/sdk.subscribe.active.route.message.ts:18


<Const> SDK_SUBSCRIBE_ACTIVE_ROUTE_EVENT_TYPE

● SDK_SUBSCRIBE_ACTIVE_ROUTE_EVENT_TYPE: "WchSdk.router.activeRoute.subscribe" = "WchSdk.router.activeRoute.subscribe"

Defined in interfaces/messages/sdk.subscribe.active.route.message.ts:9


ibm-wch-sdk-api > "interfaces/messages/sdk.subscribe.message"

External module: "interfaces/messages/sdk.subscribe.message"

Index

Interfaces

Variables


Variables

<Const> SDK_UNSUBSCRIBE_EVENT_TYPE

● SDK_UNSUBSCRIBE_EVENT_TYPE: "WchSdk.unsubscribe" = "WchSdk.unsubscribe"

Defined in interfaces/messages/sdk.subscribe.message.ts:15


ibm-wch-sdk-api > "interfaces/messages/sdk.subscribe.mode.message"

External module: "interfaces/messages/sdk.subscribe.mode.message"

Index

Enumerations

Interfaces

Variables


Variables

<Const> SDK_MODE_EVENT_TYPE

● SDK_MODE_EVENT_TYPE: "WchSdk.mode" = "WchSdk.mode"

Defined in interfaces/messages/sdk.subscribe.mode.message.ts:22


<Const> SDK_SUBSCRIBE_MODE_EVENT_TYPE

● SDK_SUBSCRIBE_MODE_EVENT_TYPE: "WchSdk.mode.subscribe" = "WchSdk.mode.subscribe"

Defined in interfaces/messages/sdk.subscribe.mode.message.ts:8


ibm-wch-sdk-api > "interfaces/messages/sdk.subscribe.route.message"

External module: "interfaces/messages/sdk.subscribe.route.message"

Index

Interfaces

Variables


Variables

<Const> SDK_ROUTE_EVENT_TYPE

● SDK_ROUTE_EVENT_TYPE: "WchSdk.router.route" = "WchSdk.router.route"

Defined in interfaces/messages/sdk.subscribe.route.message.ts:23


<Const> SDK_SUBSCRIBE_ROUTE_EVENT_TYPE

● SDK_SUBSCRIBE_ROUTE_EVENT_TYPE: "WchSdk.router.route.subscribe" = "WchSdk.router.route.subscribe"

Defined in interfaces/messages/sdk.subscribe.route.message.ts:9


ibm-wch-sdk-api > "interfaces/query"

External module: "interfaces/query"

Index

Interfaces

Type aliases


Type aliases

QueryValue

Ƭ QueryValue: * string | number | boolean *

Defined in interfaces/query.ts:4


ibm-wch-sdk-api > "interfaces/registry/v1/currenttenant/index"

External module: "interfaces/registry/v1/currenttenant/index"

Index

Variables


Variables

<Const> REL_PATH_CURRENT_TENANT

● REL_PATH_CURRENT_TENANT: "registry/v1/currenttenant" = "registry/v1/currenttenant"

Defined in interfaces/registry/v1/currenttenant/index.ts:2


ibm-wch-sdk-api > "interfaces/sdk/router/router"

External module: "interfaces/sdk/router/router"

Index

Interfaces


ibm-wch-sdk-api > "interfaces/sdk/sdk"

External module: "interfaces/sdk/sdk"

Index

Interfaces

Variables


Variables

<Const> WCH_SDK_MODULE_NAME

● WCH_SDK_MODULE_NAME: "WchSdk" = "WchSdk"

Defined in interfaces/sdk/sdk.ts:7


ibm-wch-sdk-api > "interfaces/sdk/search/search"

External module: "interfaces/sdk/search/search"

Index

Interfaces

Type aliases


Type aliases

QueryInput

Ƭ QueryInput: * string | string[] | null | undefined | URLSearchParams | Query *

Defined in interfaces/sdk/search/search.ts:7


ibm-wch-sdk-api > "interfaces/sdk/version/version"

External module: "interfaces/sdk/version/version"

Index

Interfaces


ibm-wch-sdk-api > "interfaces/user-profile/v1/users/currentuser/index"

External module: "interfaces/user-profile/v1/users/currentuser/index"

Index

Variables


Variables

<Const> REGEXP_ANONYMOUS_USER_ID

● REGEXP_ANONYMOUS_USER_ID: RegExp = /^\w{8}-\w{4}-f\w{3}-\w{4}-\w{12}$/

Defined in interfaces/user-profile/v1/users/currentuser/index.ts:2


<Const> REL_PATH_CURRENT_USER

● REL_PATH_CURRENT_USER: "user-profile/v1/users/currentuser" = "user-profile/v1/users/currentuser"

Defined in interfaces/user-profile/v1/users/currentuser/index.ts:1


ibm-wch-sdk-api > "services/hub-info/hub-info"

External module: "services/hub-info/hub-info"

Index

Interfaces


ibm-wch-sdk-api > "services/hub-info/hub-info.config"

External module: "services/hub-info/hub-info.config"

Index

Enumerations

Classes

Interfaces

Type aliases


Type aliases

HubInfoUrlProvider

Ƭ HubInfoUrlProvider: * null | undefined | URL | string | function *

Defined in services/hub-info/hub-info.config.ts:33


ibm-wch-sdk-api > "services/info/url.config"

External module: "services/info/url.config"

Index

Interfaces


ibm-wch-sdk-api > "services/logging/logger.service"

External module: "services/logging/logger.service"

Index

Interfaces


Logging

The logger interfaces allow to plug custom loggers via the LoggerFactory. In addition they expose a simple logger interface, modelled after the standard console logger.

Delivery

Typescript definitions of the WCH Delivery APIs.

WchSdk

The SDK defines the plain JS WCH SDK APIs .

Properties

  • router
  • version the current version of the SDK, including a version number and the build date

Methods

  • refresh(): causes the currently displayed data to be refreshed

The SDK is available on the global window object

window.WchSdk

Cross Origin Eventing

The SDK supports WebMessaging to allow communication across frames via the postMessage functionality. Each message sent to the SDK needs to contain a type and an id field. The type is used to identify the meaning of the message, the id to allow the caller to correlate potential responses.

Responses to messages sent to the iframe (e.g. messages back from the SDK to the parent frame) can optionally use channelMessaging. If the first element of the transfer object contains a messagePort, this will be used for reply messages or notifications. Else these replies will be sent against the parent window, directly.

Supported Message Types

  • WchSdk.refresh: refreshes the data currently displayed by the application. The message has no response.
  • WchSdk.router.navigateByPath: navigates to the specified path. Responds with a WchSdk.router.navigateByPathResponse response. Takes:
    • path: path to navigate to
  • WchSdk.router.activeRoute.subscribe: subscribes a listener for changes in the active route (i.e. navigations). The event will be responsed by a response containing a handle that can be used to unsubscribe. Whenever a navigation occurs, the SDK will send a WchSdk.router.activeRoute message to the caller.
  • WchSdk.router.route.subscribe: subscribes a listener for changes for a given route. The event will be responsed by a response containing a handle that can be used to unsubscribe. Whenever the route changes, comes into existence or is deleted, the SDK will send a WchSdk.router.route message to the caller. Takes:
    • route: a string or string array that describes the route to listen to. If the value is a string, then it must be the escaped path, starting with a slash but not ending with a slash. If it is a string array, each value represents the unescaped path segment, the segments to not contain slashes.
  • WchSdk.unsubscribe: unsubscribes from a subscription given the subscription handle
    • handle: the subscription handle

Supported Response Types

  • WchSdk.router.navigateByPathResponse: sent as a response to a WchSdk.router.navigateByPath message from the SDK to the caller. Replicates the caller message fields and in addition:
    • success: true if the navigation completed, else false
    • error: an optional error object
  • WchSdk.router.activeRoute.subscribeResponse: sent as a response to WchSdk.router.activeRoute.subscribe.
    • handle: handle to the subscription, can be used to unsubscribe
  • WchSdk.router.route.subscribeResponse: sent as a response to WchSdk.router.route.subscribe.
    • handle: handle to the subscription, can be used to unsubscribe
  • WchSdk.router.activeRoute: sent from the SDK to the subscriber for modifications in the navigation.
    • page: The selected page. Will be null if this is the last event (e.g. because of an application shutdown)

Examples

Listen for Navigation Events

This example shows how a parent frame can listen for navigation events of an SPA. The example uses channelMessaging to establish a direct communication channel from the SDK to the parent frame. Navigation events will be sent via this channel.

Note that the use of a channel is not required. If no channel is passed in, the navigation events will be sent directly to the parent window via postMessage.

The example doe NOT show how to unsubscribe.

/**
 * Message sent to the SDK to subscribe for navigation notifications
*/
var msg = {
	type: 'WchSdk.router.activeRoute.subscribe',
	id: 'someid'
};

// use a message channel to receive the responses
var channel = new MessageChannel();

/** Perform  the subscription, transfer one end of the channel to the SDK.
 * Note that the second parameter is the origin of the iframe.
*/
myframe.contentWindow.postMessage(msg, "http://localhost:4200", [channel.port2]);

/**
 * Listen for changes in the navigation
 * We expect two types of callbacks here, one for each navigation event
 * and a response sending the subscription handle, so we can unsubscribe later.
 */
channel.port1.addEventListener('message', msg => {
  // check for the message type
  const data = msg.data;
  if (data.type === 'WchSdk.router.activeRoute') {
    // log the active route
	console.log('navigation in iframe', data.page.route);
  } else
  if (data.type === 'WchSdk.router.activeRoute.subscribeResponse') {
	console.log('subscription handle', data.handle);
  }

});
// start the bi-directional communication
channel.port1.start();

Messaging

Cross Origin Eventing

The SDK supports WebMessaging to allow communication across frames via the postMessage functionality. Each message sent to the SDK needs to contain a type and an id field. The type is used to identify the meaning of the message, the id to allow the caller to correlate potential responses.

Responses to messages sent to the iframe (e.g. messages back from the SDK to the parent frame) can optionally use channelMessaging. If the first element of the transfer object contains a messagePort, this will be used for reply messages or notifications. Else these replies will be sent against the parent window, directly.

Supported Message Types

  • WchSdk.refresh: refreshes the data currently displayed by the application. The message has no response.
  • WchSdk.router.navigateByPath: navigates to the specified path. Responds with a WchSdk.router.navigateByPathResponse response. Takes:
    • path: path to navigate to
  • WchSdk.router.activeRoute.subscribe: subscribes a listener for changes in the active route (i.e. navigations). The event will be responsed by a response containing a handle that can be used to unsubscribe. Whenever a navigation occurs, the SDK will send a WchSdk.router.activeRoute message to the caller.
  • WchSdk.router.route.subscribe: subscribes a listener for changes for a given route. The event will be responsed by a response containing a handle that can be used to unsubscribe. Whenever the route changes, comes into existence or is deleted, the SDK will send a WchSdk.router.route message to the caller. Takes:
    • route: a string or string array that describes the route to listen to. If the value is a string, then it must be the escaped path, starting with a slash but not ending with a slash. If it is a string array, each value represents the unescaped path segment, the segments to not contain slashes.
  • WchSdk.unsubscribe: unsubscribes from a subscription given the subscription handle
    • handle: the subscription handle

Supported Response Types

  • WchSdk.router.navigateByPathResponse: sent as a response to a WchSdk.router.navigateByPath message from the SDK to the caller. Replicates the caller message fields and in addition:
    • success: true if the navigation completed, else false
    • error: an optional error object
  • WchSdk.router.activeRoute.subscribeResponse: sent as a response to WchSdk.router.activeRoute.subscribe.
    • handle: handle to the subscription, can be used to unsubscribe
  • WchSdk.router.route.subscribeResponse: sent as a response to WchSdk.router.route.subscribe.
    • handle: handle to the subscription, can be used to unsubscribe
  • WchSdk.router.activeRoute: sent from the SDK to the subscriber for modifications in the navigation.
    • page: The selected page. Will be null if this is the last event (e.g. because of an application shutdown)

Examples

Listen for Navigation Events

This example shows how a parent frame can listen for navigation events of an SPA. The example uses channelMessaging to establish a direct communication channel from the SDK to the parent frame. Navigation events will be sent via this channel.

Note that the use of a channel is not required. If no channel is passed in, the navigation events will be sent directly to the parent window via postMessage.

The example doe NOT show how to unsubscribe.

/**
 * Message sent to the SDK to subscribe for navigation notifications
*/
var msg = {
	type: 'WchSdk.router.activeRoute.subscribe',
	id: 'someid'
};

// use a message channel to receive the responses
var channel = new MessageChannel();

/** Perform  the subscription, transfer one end of the channel to the SDK.
 * Note that the second parameter is the origin of the iframe.
*/
myframe.contentWindow.postMessage(msg, "http://localhost:4200", [channel.port2]);

/**
 * Listen for changes in the navigation
 * We expect two types of callbacks here, one for each navigation event
 * and a response sending the subscription handle, so we can unsubscribe later.
 */
channel.port1.addEventListener('message', msg => {
  // check for the message type
  const data = msg.data;
  if (data.type === 'WchSdk.router.activeRoute') {
    // log the active route
	console.log('navigation in iframe', data.page.route);
  } else
  if (data.type === 'WchSdk.router.activeRoute.subscribeResponse') {
	console.log('subscription handle', data.handle);
  }

});
// start the bi-directional communication
channel.port1.start();

ibm-wch-sdk-api

Index

External modules