Registry / web-framework / js-component-framework

js-component-framework

JSON →
library3.2.0jsnpmunverified

JS Component Framework is a zero-dependency JavaScript library designed to simplify the configuration and attachment of JavaScript components to DOM elements. It is currently at stable version 3.2.0, with recent updates focusing on bug fixes and enhanced flexibility, such as improved `domContentLoaded` handling and custom root selector support. The framework allows components to be defined as either ES6 classes or functions, using `componentProvider` to automatically initialize them based on a configuration object. A key differentiator is its automatic collection of child nodes based on configuration, minimizing the need for manual DOM queries within components. This approach aims to streamline front-end development by centralizing DOM interaction logic and reducing boilerplate, offering a lightweight alternative to more comprehensive frameworks.

npm install js-component-framework
INSTALL
IMPORT
SIG · JS-COMPONENT-FRAME
J
js-component-framework
web-frameworkjavascriptv3.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

componentProvider
import { componentProvider } from 'js-component-framework';
const componentProvider = require('js-component-framework');
The `componentProvider` is the central export for configuring and initializing components in v3. `require()` is not supported in modern ESM contexts.
Component (v2 compatibility)
import { Component } from 'js-component-framework/v2';
import { Component } from 'js-component-framework';
For projects migrating from v2 or needing core v2 functionality, the `Component` export is available via the `/v2` subpath. V3 uses `componentProvider` instead.
componentLoader
import { componentLoader } from 'js-component-framework';
import componentLoader from 'js-component-framework';
`componentLoader` is exported individually for cases where automatic loading by `componentProvider` is not desired. It is a named export.

Demonstrates how to define an ES6 class component, configure its properties including child selectors and options, and initialize it using `componentProvider` for automatic DOM attachment and event handling.

import { componentProvider } from 'js-component-framework'; // 1. Define your HTML component structure with a data-component attribute // <div data-component="my-greeting-component"> // <h2 class="greeting-title"></h2> // <button data-action="say-hello">Say Hello</button> // </div> // 2. Create your ES6 class or function component class MyGreetingComponent { constructor({ element, children, options }) { this.element = element; // The root DOM element (e.g., <div data-component="my-greeting-component">) this.title = children.title; // Child element mapped by querySelector this.sayHelloButton = children.sayHelloButton; // Child element mapped by querySelectorAll (or querySelector if unique) this.message = options.message; // Arbitrary options passed in config if (this.title) { this.title.textContent = this.message || 'Hello from Component!'; } if (this.sayHelloButton) { this.sayHelloButton.addEventListener('click', this.handleSayHello.bind(this)); } } handleSayHello() { alert(`Component says: ${this.message || 'Hello world!'}`); } } // 3. Define the component configuration const myGreetingConfig = { name: 'my-greeting-component', component: MyGreetingComponent, querySelector: { title: '.greeting-title' }, querySelectorAll: { sayHelloButton: '[data-action="say-hello"]' }, options: { message: 'Welcome to the JS Component Framework!' }, load: true // Automatically initialize on DOMContentLoaded }; // 4. Initialize the component using componentProvider componentProvider(myGreetingConfig); // Example of deferred loading (if config.load was false) /* const myDeferredComponentProvider = componentProvider({ ...myGreetingConfig, name: 'my-other-component', load: false }); window.addEventListener('load', () => { myDeferredComponentProvider(); // Manually initialize the component }); */
Debug
Known issues
breakingVersion 3.0.0 introduced significant breaking changes, including a reimagined framework core that removes unused features, simplifies component structure, and centers around `componentProvider`. Existing projects on v2.x or earlier will require updates to component definitions and initialization patterns.
fix
Refer to the official 'Updating to v3' documentation in the GitHub Wiki for a comprehensive upgrade guide. Components must be adapted to either ES6 classes or functions, configured via `componentProvider`.
affects: >=3.0.0
breakingStarting with version 2.1.0, the framework embraced ES Modules. While v2.1.0 allowed both, v3.0.0+ is primarily designed for and expects ES Module imports. Using CommonJS `require()` syntax may lead to errors in modern build environments or direct browser usage.
fix
Ensure all imports use ES Module `import` syntax (e.g., `import { componentProvider } from 'js-component-framework';`). Update build configurations to handle ES Modules correctly if necessary.
affects: >=3.0.0
gotchaIn versions prior to 3.2.0, the `domContentLoaded` handler (default for `config.load`) could execute the component initialization callback more than once, leading to unintended side effects or multiple component instances.
fix
Upgrade to version 3.2.0 or newer to benefit from the fix that ensures the `domContentLoaded` callback executes only once. Alternatively, implement custom debouncing or flag checks in older versions if `config.load` relies on `DOMContentLoaded`.
affects: <3.2.0
gotchaThe `config.load` property gained a new `true` option in v3.2.0 to immediately execute the provider function upon script parsing. Previous versions only supported `false` (return provider), an `[HTMLElement, event]` array, or a custom `handler` function.
fix
For immediate loading in versions prior to 3.2.0, a custom `handler` function wrapping the provider call could be used. For `true` functionality, upgrade to v3.2.0+.
affects: <3.2.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use CommonJS `require()` syntax in a modern JavaScript environment (browser, or Node.js with 'type: module') where `js-component-framework` is imported as an ES Module.
fix
Refactor your import statements to use ES Module syntax: `import { componentProvider } from 'js-component-framework';`.
TypeError: (0, _js_component_framework__WEBPACK_IMPORTED_MODULE_0__.componentProvider) is not a function
Incorrectly importing `componentProvider` as a default import or with a wrong named import when it is exported as a named export. This often happens with bundlers like Webpack.
fix
Ensure `componentProvider` is imported as a named export: `import { componentProvider } from 'js-component-framework';`.
Component 'my-component-name' not found in DOM for initialization.
The `name` property in the component configuration does not match any `data-component` attribute in the DOM, or the `root` selector is incorrect, preventing the framework from finding the target element(s).
fix
Verify that the `name` property in your component configuration exactly matches the `data-component` attribute value on your HTML element. Alternatively, if using `root`, ensure the CSS selector is correct and targets existing elements.
Error: `config.component` must be a function or a class.
The `component` property in the configuration object was not provided as an ES6 class or a function, which are the only supported types for component definitions in v3.
fix
Ensure your `config.component` property points to an actual ES6 class or a JavaScript function that defines your component's logic. Anonymous functions or arrow functions are valid if assigned correctly.
Upgrade
Version history
3.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources