Hello. I would like to share and propose some ideas for configuring modules' and their exported contents and functionalities. Below are indicated some of the existing ways to do this (examples 1, 2, and 3) and a proposed new syntax concept (example 4).
Example 1: Basic Import with Configuration Object
// config.js
export const config = {
base: 'https://api.example.com'
};
// main.js
import { config } from './config.js';
import { initialize } from './module.js';
initialize(config);
Example 2: Named Imports with Configuration
// module.js
export function initialize(config) {
console.log('Initializing with config:', config);
}
export function fetchData(endpoint) {
// Fetch data logic
}
// main.js
import { initialize, fetchData } from './module.js';
const config = {
base: 'https://api.example.com'
};
initialize(config);
fetchData('/data-endpoint');
Example 3: Default Import with Configuration
// module.js
export default function initialize(config) {
console.log('Initializing with config:', config);
}
// main.js
import initialize from './module.js';
const config = {
base: 'https://api.example.com'
};
initialize(config);
Example 4: New Syntax Concepts for Discussion
import { config } from './config.js';
import { widget } from './module.js' using config;
import { config } from './config.js';
import { widget } from './module.js' using { configuration: config };
import { widget } from './module.js' using { base: 'https://api.example.com' };
As envisioned, modules would receive these provided configuration objects, e.g., as special global values, to make use of to configure their exported contents and functionalities.
Thank you for any comments or feedback on these ideas.