The application code launcher of the Design System.
Overview
This component will perform several tasks:
- Test browser capabilities (Javascript feature support, Browser APIs).
- Inject a polyfill bundle that covers the unsupported features in the document.
- Set up your application code to be executed on the
'DOMContentLoaded'
event once the polyfills have finished loading.
A polyfill is a piece of code that implements a feature not supported by the current runtime environment.
We have two polyfill bundles, one for very old browsers (full), and another for mid tier browsers (partial). Modern browsers usually don't need loading polyfills.
Usage
Dependencies
To get the app-loader working, include the dependencies in your project in the following order:
"design-system": "git+ssh://git@github.com/Selectra-Dev/design-system.git"
import appLoader from 'design-system/src/js/00-utilities/app-loader';
Basic code
To use the app-loader, our application code first must be wrapped into a function. We'll then pass a reference to this function to the app-loader, and optionally a list of features our code need to function.
The app-loader will then test the capabilities of the browser, and conditionally inject a polyfill bundle before setting up the code to be called back when the DOM has finished loading.
import appLoader from 'design-system/src/js/00-utilities/app-loader';
function app() {
// We use 'classList' property in our code...
document.body.classList.add( 'lol' );
// And the 'fetch' API !
let randomFetch =
fetch( 'https://selectra.info/')
.then( response => {
return response.text()
})
}
// No worries! We'll load some polyfills if the browser does not support
// some of these features.
appLoader({
// The 'app' function will be set to be called back on the
// 'DOMContentLoaded' event. After the polyfills are loaded.
appCode: app,
// We pass the list of features our application needs to function.
// This is an optional step.
appRequiredFeatures:
[
// Sub Array for Element's features.
[
'element',
[
'classList'
]
],
// Sub Array for Fetch API
[
'fetch',
[
'all'
]
]
]
});
Function call
appLoader( init );
# | Name | Type | Default | Required | Description |
---|---|---|---|---|---|
1 | init | Object |
/ | Yes | A configuration object. |
|
Feature list
Here's a comprehensive list of features covered by the DS polyfill bundles.
Core Javascript
Built-In | ID | Feature | Bundle |
---|---|---|---|
number | isinteger | Number.isInteger() | Full |
number | parseInt | Number.parseInt() | Full |
number | parseFloat | Number.parseFloat() | Full |
array | from | Array.from() | Full |
array | forEach | Array.prototype.forEach() | Full |
array | includes | Array.prototype.includes() | Full |
array | from | Array.prototype.slice() | Full |
math | sign | Math.sign() | Full |
string | fromCodePoint | String.fromCodePoint() | Full |
string | codePointAt | String.prototype.codePointAt() | Full |
string | includes | String.prototype.includes() | Full |
string | repeat | String.prototype.repeat() | Full |
object | assign | Object.assign() | Full |
symbol | all | Symbol | Full |
promise | all | Promise | Full |
Browser APIs & Interfaces
API / Interface | ID | Feature | Bundle |
---|---|---|---|
parentNode | append | ParentNode.append() | Full |
element | closest | Element.closest() | Full |
element | matches | Element.matches() | Full |
element | classList | Element.classList() | Full |
scroll | all | ScrollToOptions | Full, Partial |
intersectionObserver | all | IntersectionObserver | Full, Partial |
fetch | all | fetch() | Full, Partial |
positionSticky | all | position: sticky | Full, Partial |