npm.io
4.10.0 • Published 1h ago

@open-pioneer/runtime

Licence
Apache-2.0
Version
4.10.0
Deps
11
Size
441 kB
Vulns
0
Weekly
0
Stars
4

@open-pioneer/runtime

Implements the runtime environment for Open Pioneer Trails apps. The package also provides services for app development.

Quick start

Import the createCustomElement function from this package to create your application as a Web Component:

// my-app/app.ts
import { createCustomElement } from "@open-pioneer/runtime";
import * as appMetadata from "open-pioneer:app";
import { AppUI } from "./AppUI";

const Element = createCustomElement({
    component: AppUI,
    appMetadata
});

customElements.define("my-app", Element);

In this example, Element is a custom web component class registered as <my-app>. The application renders the AppUI (a React component) and automatically contains the services, styles etc. of its package dependencies. HTML sites or JavaScript code can now instantiate the application by creating a DOM-Element:

<!-- some-site/index.html -->
<!doctype html>
<html>
    <body>
        <!-- Contains the app once the script has been loaded -->
        <my-app></my-app>
        <script type="module" src="/apps/my-app/app.ts"></script>
    </body>
</html>

Error screen

If a hard error occurs on application start, the AppUI cannot be rendered but an error screen is shown instead. The error screen shows a message to the user that an error occurred on application start. The error screen is available in English (fallback) and German.

If the application was started in development mode, the error screen shows additional information about the error and the stack trace.

Provided services

The package contains services that provide different functionalities useful for app development. For details, see the API description of the respective service.

ApplicationContext

The ApplicationContext provides access to global application values, e.g. the web component's host element and the root node.

LocaleService

The LocaleService provides the current locale and the supported message locales, and switches the locale at runtime.

ThemeService

The ThemeService controls the color mode and the Chakra system config of the app.

NumberParserService

The NumberParserService provides a method to parse a string to a number according to the current locale.

License

Apache-2.0 (see LICENSE file)

Keywords