Utility functions for WebApps.
Requirements
Section titled “Requirements”@soleil/sv-gulp-build 4 or later (Works best with ^4.3.0).
Install
Section titled “Install”yarn add @soleil-se/app-util@^4.0.0
Migration
Section titled “Migration”Migrating from version 2 or 3? See MIGRATION.
All imports from base package are available both on the server and client.
appId : String
Section titled “appId : String”DOM friendly unique identifier for the WebApp.
import { appId } from '@soleil-se/app-util';
console.log(appId); // For example: 12_682d461b1708a9bb1ea13efdisOffline : Boolean
Section titled “isOffline : Boolean”If the WebApp is running in offline mode or not.
import { isOffline } from '@soleil-se/app-util';
console.log(isOffline); // true or falseisOnline : Boolean
Section titled “isOnline : Boolean”If the WebApp is running in online mode or not.
import { isOnline } from '@soleil-se/app-util';
console.log(isOnline); // true or falsegetNamespace([prefix]) ⇨ String
Section titled “getNamespace([prefix]) ⇨ String”Get a prefixed namespace unique for app.
Returns: String - Prefixed namespace.
| Param | Type | Default |
|---|---|---|
| [prefix] | string | "'app'" |
import { getNamespace } from '@soleil-se/app-util';
console.log(getNamespace());// For example: app_12_682d461b1708a9bb1ea13efd
console.log(getNamespace('input'));// For example: input_12_682d461b1708a9bb1ea13efd
// If the app is in a decoration template the Portlet ID is the same for all instances, so the ID of the decorated node is used as well.console.log(getNamespace('decoration'));// For example: decoration_10_3871c02f1754f3aa8f9d4eb_12_70c3d424173b4900fc550e1cgetRouteUri(route) ⇨ String
Section titled “getRouteUri(route) ⇨ String”Get URI for a route.
Returns: String - URI for route.
| Param | Type | Description |
|---|---|---|
| route | String | A route. |
import { getRouteUri } from '@soleil-se/app-util';
console.log(getRouteUri('/items'));// URI structure: /appresource/<pageId>/<portletId>/itemsgetViewUri(route) ⇨ String
Section titled “getViewUri(route) ⇨ String”Get URI for a view.
Returns: String - URI for view.
| Param | Type | Description |
|---|---|---|
| route | String | A route. |
import { getViewUri } from '@soleil-se/app-util';
console.log(getViewUri('/items'));// URI structure: ?sv.target=<id>&sv.<id>.route=/itemsgetResourceUri(resource) ⇨ String
Section titled “getResourceUri(resource) ⇨ String”Get URI for a resource.
Returns: String - URI for a resource.
| Param | Type | Description |
|---|---|---|
| resource | String | A resource. |
import { getResourceUri } from '@soleil-se/app-util';
console.log(getResourceUri('/image.png'));// URI structure: /webapp-files/<webappname>/<webappversion>/image.pnggetAppProps([key]) ⇨ * | Object
Section titled “getAppProps([key]) ⇨ * | Object”Get props that are passed to app when rendering.
Returns: * | Object - Value or object.
| Param | Type | Description |
|---|---|---|
| [key] | String | Key for value. |
import { getAppProps } from '@soleil-se/app-util';
// Get value with keyconst myValue = getAppProps('myValue');// Or with destructuringconst { myValue } = getAppProps();getAppData([key]) ⇨ * | Object (DEPRECATED)
Section titled “getAppData([key]) ⇨ * | Object (DEPRECATED)”Use getAppProps instead.
Get props that are passed to app when rendering.
Returns: * | Object - Value or object.
| Param | Type | Description |
|---|---|---|
| [key] | String | Key for value. |
import { getAppData } from '@soleil-se/app-util';
// Get value with keyconst myValue = getAppData('myValue');// Or with destructuringconst { myValue } = getAppData();