
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
crs-modules
Advanced tools
CRS modules allows you to define modules based on keys. The aim is to load modules only when required. Under normal conditions you would just use the import language feature. When working with schema driven UI however you may want to have something
CRS modules allows you to define modules based on keys.
The aim is to load modules only when required.
Under normal conditions you would just use the import language feature.
When working with schema driven UI however you may want to have something that will dynamically load modules based on the features defined in the modules.
This library aims to be used alongside packages such as crs-schema and crs-components for the above example.
If you are using crs-binding you can extend the binding engine to auto load modules for web components when it parses the dom elements.
await crs.modules.enableBinding([
["my-component", "/components/my-component.js"],
["other-component", "/components/other-components.js"]
]);
The parameter is an array of module registries.
When you are done with the modules, call dispose to clear resources
Clear all resources registered on modules
Add new module to load providing a key and value pair.
await crs.modules.add("module-name", "/app/function-test.js");
Remove a module from the registry.
await crs.modules.remove("module-name");
Load and get the module from the registry for further use.
await crs.modules.get("module-name");
Load the module and return the default exported module item.
const fn = await this.getDefault("module-name");
Get the prototype used to instantiate a class
const proto = await this.getPrototype(key, className);
const intance = new proto();
Create a class instance defined on the module.
await crs.modules.getInstanceOf("module-name", "ClassName", param1, param2);
Parameters are sent to the constructor.
If the key and class name is the same you don't need to define the class name.
await crs.modules.getInstanceOf("Test");
Create a class instance that is exported as the default
await crs.modules.getInstanceOfDefault("module-name");
Call a function defined on the module.
await crs.modules.call("module-name", null, "functionTest", param1, param2);
If the key and the function name is the same you don't need to define the function name.
await crs.modules.call("lib");
Call a function that is set as the default export.
await crs.modules.callDefault("default", null, "Hello World");
In some cases you can use a convention over code method to register modules.
This means you don't need to load each module individually but load it based on a location.
This works a little different between auto-loading component files vs library files.
To register a component location
await crs.modules.addComponentLocation("pv", "/components");
To register a module location
await crs.modules.addModuleLocation('pv', "../modules");
Since component registry is separate from the module registry, you can reuse the sake key.
Components using locations
<test-component data-module="pv"></test-component>
Using this option, when crs-binding processes the element it will see you have a module location defined on the component and load it using a naming convention. The convention works like this.
`${location}/${nodeName}/${nodeName}.js` // "/components/test-component/test-component.js"
executing features on path
const result = await crs.modules.call("pv:my-module", "whoAmI");
This example shows how you use a location key with the module name.
This also uses a convention over code.
`${location}/${module}.js` // "/modules/my-module.js"
If you don't want to use the file name, you will need to register the module with
await crs.modules.add("module-name", "/app/function-test.js");
FAQs
CRS modules allows you to define modules based on keys. The aim is to load modules only when required. Under normal conditions you would just use the import language feature. When working with schema driven UI however you may want to have something
We found that crs-modules demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.