Utility functions for WebApps.
Requirements
@soleil/sv-gulp-build
4 or later (Works best with ^4.3.0).
Install
yarn add @soleil-se/app-util@^4.0.0
Migration
Migrating from version 2 or 3? See MIGRATION.
API
All imports from base package are available both on the server and client.
String
appId : DOM friendly unique identifier for the WebApp.
import { appId } from '@soleil-se/app-util';
console.log(appId); // For example: 12_682d461b1708a9bb1ea13efd
Boolean
isOffline : If the WebApp is running in offline mode or not.
import { isOffline } from '@soleil-se/app-util';
console.log(isOffline); // true or false
Boolean
isOnline : If the WebApp is running in online mode or not.
import { isOnline } from '@soleil-se/app-util';
console.log(isOnline); // true or false
String
getNamespace([prefix]) ⇨ 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_70c3d424173b4900fc550e1c
String
getRouteUri(route) ⇨ 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>/items
String
getViewUri(route) ⇨ 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=/items
String
getResourceUri(resource) ⇨ 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.png
*
| Object
getAppProps([key]) ⇨ 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();
*
| Object
(DEPRECATED)
getAppData([key]) ⇨ 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();