CodeCoupler Application Basics Service Worker Loader Vue 🔒
What is this?
This Vue component uses @codecoupler-pro/app-service-worker to display an icon indicating the status of the service worker. Four different icons are displayed depending on the status: Loading, OK, Error, and Update Available.
If an update is available, a pop-up will appear below the button to alert the user to install it.
Clicking the icon displays a dropdown menu that offers the user the following options depending on the status: Check for updates, Install update, Reload page (in case of an error).
In addition, the current version number of the service worker is displayed, as well as an error message if an error occurs.
The component uses bootstrap in combination with @popperjs/core to display the dropdown and the
popup.
Setup
Install Bundle:
Define Aliases, Externals and Assets:
Basic Usage
Use it with JavaScript:
Use it as a CodeCoupler Costa Component:
Use it as Vue component:
Styling
The following identifiers can be used in the following:
- error
- loading
- ok
- update
- reload
- lookup
- update-now
CSS Classes:
The icons will use the class icon and the identifier as classname.
Override default icons:
You can override the default icons using the property iconsComponent. Create a Vue file with
multiple svg icons and tag them with v-if like shown below. Place them all in one span element.
Define then one prop icon:
| icons-component-custom.vue | |
|---|---|
Import this file and use this as prop:
Dropdown Menu and Items
The dropdown menu will be rendered into the body of the document. For this reason, in addition to
the dropdown-menu class, you can assign an additional class to the dropdown using the
dropdownClasses prop to target it more precisely.
Each dropdown item has the class dropdown-item. In addition, the element used and the additional
class define the type of content:
| Element | Class | Relevant Inner Elements |
|---|---|---|
| div | error | p, code |
| a | reload | span (using icon classes), span.text |
| a | loading | span (using icon classes), span.text |
| a | lookup | span (using icon classes), span.text |
| a | update-now | span (using icon classes), span.text |
| div | version | No Elements, Only Text |
Reference
The following props can be passed:
swLoader: Object-
ServiceWorkerLoader instance.
dropdownClasses: String-
Additional class names for dropdown menu element. The specified classes will be set via the
setClassfunction from the@codecoupler/dom-bundlepackage. You can provide one or more class names as a string of space-separated values or as an array of strings. See above. popupClasses: String-
Additional class names for dropdown menu element. The popup will be rendered into the
bodyof the document. For this reason, in addition to thepopupclass, you can assign an additional class to the popup using thepopupClassesprop to target it more precisely. iconsComponent: Vue-
Overrides the default icons. See above.
texts: Object-
Redefine all texts here:
showIcons: Object-
To show the icons regardless of the current status you can pass the identifier as properties and the value
trueto this object. Example:{ identifier1: true }. swUpdateLocation: StringandswUpdateLocationForced: String-
History replacement in case of an service loader update or a forced service loader update. The default values are
/#sw-updateand/#sw-update-forced. swDebugUpdateAvailable: Boolean-
If
truean available update is simulated. The update can be started, and the browser is forced to reload the ServiceWorker.