WebApps 2

app

app is available in both a server and client side context and holds some data about the module and it's context.

In a client side context app could also be used to send triggers or data within the WebApp.

import app from "@sitevision/api/common/app";

Properties

app.defaultLocale

The default locale of the module

app.locale

The locale of the module

app.portletId

The module's identifier

app.webAppId

The WebApp identifier. Specified in the manifest.

app.webAppVersion

The active version of the WebApp

app.defaultLocale // en
app.locale        // sv
app.portletId     // 12.xxxx
app.webAppId      // myWebApp
app.webAppVersion // 1.2

Methods

The methods are available in a client side context to trigger and send events within a WebApp.

app.trigger(key [, data...])

Triggers an event within the WebApp.

// Trigger an app event
app.trigger("add:item");

// Trigger an app event with data
app.trigger("add:items", 3, 'banana');

app.on(key, () => {})

Listen to an event.

// Listen to an app event
app.on("add:item", () => {
   console.log("Item added");
   // Item added
});

// Listen to an app event with data
app.on("add:items", (count, item) => {
   console.log(`Added ${count} ${item}`);
   // Added 3 banana
});