Constructor
new App(containeropt, configopt)
Create an app instance
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
container | HTMLElement | | <optional> | null | The root container of the application. If null, creates a new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
config | object | <optional> | {} | Application configuration object Properties
|
- Source
If not running in browser environment
- Type
- Error
If container is not an HTMLElement
- Type
- Error
// Basic app setup
const container = document.querySelector('#app');
const app = new IF.App(container, {
app: { title: 'My Application' },
router: { mode: 'url' },
l18n: { defaultLanguage: 'en' }
});
// Register states
app.stateManager.add(HomeState, AboutState, UserState);
// Start the application
await app.run();// Multiple app instances
const app1 = new IF.App(container1, { app: { id: 'main-app' } });
const app2 = new IF.App(container2, { app: { id: 'widget-app' } });
// Access by ID
const mainApp = IF.App.get('main-app');// Cleanup when done
await app.destroy(); // Properly cleans up all resourcesExtends
Members
POOL :Object.<string, App>
Global pool of all app instances
- Object.<string, App>
- Source
Methods
addEventListener(type, listener)
Add an event listener for a specific event type
| Name | Type | Description |
|---|---|---|
type | string | Event type to listen for |
listener | function | | Callback function or event listener object |
- Overrides
- Source
// Function listener
app.addEventListener('customEvent', (event) => {
console.log('Custom event fired:', event.detail);
});// Object listener
const listener = {
handleEvent(event) {
console.log('Event:', event.type);
}
};
app.addEventListener('myEvent', listener);(async) destroy() → {Promise.<void>}
Destroys InfrontJS application instance and cleans up all resources This method properly disposes of all subsystems, removes event listeners, cleans up the DOM, and removes the app from the global pool.
- Source
- Type:
- Promise.<void>
// Cleanup when app is no longer needed
await app.destroy();// Cleanup before page navigation
window.addEventListener('beforeunload', async () => {
await app.destroy();
});// Switch between apps
await oldApp.destroy();
const newApp = new IF.App(container, newConfig);
await newApp.run();dispatchEvent(event) → {boolean}
Dispatch an event to all registered listeners Executes all listeners in the order they were added.
| Name | Type | Description |
|---|---|---|
event | Event | | Event object to dispatch. Use CustomEvent for custom data. |
- Overrides
- Source
True unless event.preventDefault() was called
- Type:
- boolean
// Dispatch simple event
app.dispatchEvent(new Event('refresh'));// Dispatch event with data
app.dispatchEvent(new CustomEvent('userLogin', {
detail: {
userId: 123,
username: 'john',
timestamp: Date.now()
}
}));// Cancelable event
const event = new CustomEvent('beforeSave', {
detail: { data: formData },
cancelable: true
});
const allowed = app.dispatchEvent(event);
if (!allowed) {
console.log('Save was prevented');
}getVersion() → {string}
Get InfrontJS version
- Source
Version string (e.g., '1.0.0-rc9')
- Type:
- string
const version = app.getVersion();
console.log('Running InfrontJS', version);removeEventListener(type, listener)
Remove an event listener for a specific event type
| Name | Type | Description |
|---|---|---|
type | string | Event type to remove listener from |
listener | function | | The exact listener function or object to remove |
- Overrides
- Source
// Remove specific listener
const handler = (e) => console.log('Event fired');
app.addEventListener('myEvent', handler);
app.removeEventListener('myEvent', handler);// One-time event listener pattern
const onceHandler = (e) => {
console.log('This runs only once');
app.removeEventListener('myEvent', onceHandler);
};
app.addEventListener('myEvent', onceHandler);(async) run(routeopt) → {Promise.<void>}
Run application logic and activate routing This is an asynchronous function that starts the application lifecycle. It enables the router and processes the initial route.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
route | string | | <optional> | null | Initial route to navigate to. If null, uses current URL |
- Source
- Type:
- Promise.<void>
// Start with current URL
await app.run();// Start at specific route
await app.run('/dashboard');// Complete startup flow
const app = new IF.App(container, config);
app.stateManager.add(HomeState, AboutState);
// Load translations before starting
await app.l18n.loadTranslations('en', '/locales/en.json');
// Start application
await app.run('/home');(static) get(uidopt) → {App|null}
Get an app instance from the global pool by UID
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
uid | string | | <optional> | null | Unique identifier of the app. If null, returns the first app in the pool. |
- Source
The app instance or null if not found
- Type:
- App |
null
// Get specific app
const app = IF.App.get('my-app-id');// Get first app (useful for single-app setups)
const app = IF.App.get();