
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@netcentric/component-loader
Advanced tools
Description
npm install @netcentric/component-loader
important!
This module is not transpiled. If your project is excluding node_modules
you will have to update regex to include this module.
Eg:
// webpack babel-loader config
module.exports = {
exclude: /node_modules\/(?!@netcentric)/,
loader: 'babel-loader',
...
};
Here we are excluding node_modules, except the ones under node_modules/@netcentric/*
register({ componentName: ComponentClass });
runComponent('componentName');
or initialize all components
run();
<div data-nc="componentName"
data-nc-params-componentName="{}"></div>
import { register } from '@netcentric/component-loader';
class Text {
...
}
// register your component to be loaded
register({ Text });
import {
observe,
run
} from '@netcentric/component-loader';
// Run all registered component
run();
// Optional: Use observe to initialize new components which are added to the DOM after initial run.
observe();
This version uses standalone functions to allow tree shaking and to only use necessary parts.
Adding one component
<div data-nc="Component1"
data-nc-params-Component1="{}"></div>
Adding more than one component
<div data-nc="Component1,Component2"
data-nc-params-Component1="{}"
data-nc-params-Component2="{}"></div>
Defering component instantiation until it enters the viewport
<div data-nc="Component1"
data-nc-loading="lazy"></div>
This method will register components constructor in loaderComponents You can register individual component, or list
/**
* Constant with a object that contain collection of components classes.
*
* @param {object} newComponents - Components collection { name: definition }
* @param {number} [level] - level of inheritance
*/
const register = (newComponents, level) => {}
import { register } from '@netcentric/component-loader';
import { title } from 'components/title';
import { text } from 'components/text';
// Add 2 components named title, and text
register({ title, text });
Or you can register several components based on proper named exports
import { register } from '@netcentric/component-loader';
import * as components from 'components';
// register all components exported as proper named exports on components/index.js
register({ components });
Level is used in multilevel inheritance, eg if you have one base project with component HTML, and want to override just JS part in sub project
import { register } from '@netcentric/component-loader';
class Title {
init() {
console.log('level 0 Title');
}
}
register({ Title }, 0);
import { register, components } from '@netcentric/component-loader';
class Title extends components[0].Title {
init() {
console.log('level 1 Title');
}
}
register({ Title }, 1);
This will run the loader on previously registered components.
/**
* Run the loader on a element to get all attributes that corresponds to a component
* @param {HTMLElement} [element] root element
* @param {string} [initAttr] attribut name
*/
const run = (element = window.document, initAttr = 'data-nc') => {}
import {
register,
run
} from '@netcentric/component-loader';
// eg components
import { title } from 'components/title';
import { text } from 'components/text';
// Add 2 components named title, and text
register({ title, text });
// then you run so it will create if any HTMLelement with a default attribute have any component to start
run();
// Or load components only on a specific element and search a different attribute like `data-components`
const main = document.querySelector('main');
run(main, 'data-components');
Here is just a constant to store the available constructors (functions or classes) of components. We store it on its own file so it can be imported into separated files and without having to import the other components logic.
If you want to access all components constructors you can just import it in any file like:
import { components } from '@netcentric/component-loader';
This object will store all instances of components separated by [className][instanceId]. We store it on its own file, so it can be imported into separated files and without having to import the other components logic.
If you want to access all the instances of components you can just import it in any file like:
import { instances } from '@netcentric/component-loader';
const howManyTitles = instances.title.length;
// eg of querying title components by uuid
const getTitleByUUID = (uuid) => instances.title.filter(instance => instance.el.uuid === uuid);
const mytitle = getTitleByUUID('a8c405b5-1928-46ed-afa1-5a0a3f4dde6c');
FAQs
Load components for plain javascript projects
The npm package @netcentric/component-loader receives a total of 0 weekly downloads. As such, @netcentric/component-loader popularity was classified as not popular.
We found that @netcentric/component-loader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.