
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.
command-queue-module
Advanced tools
Create simple command queue proxies for modules.
You can boost the initial load performance of a page by requesting some non-crucial scripts asynchronously, but at the same time you might need to queue some calls to these libraries early on.
A common example is event / error tracking - it's not necessary to start sending events right after load, but it's beneficial to start collecting them as early as possible.
This project enables you to create proxy module for any library with the exact same API as the original, but the method calls are stored as commands and invoked only after the actual implementation is loaded.
createCommandQueueModule(methodNames, loadCallback)
methodNames
Type: Array<string>
Array of method names that will be proxied by the command queue. Other methods will not be available neither before or after load.
loadCallback
Type: (onLoad: (actualModule) => void) => void
Callback called right after calling createCommandQueueModule
. It should accept onLoad
function as it's only argument.
onLoad
should be called with the actual module object when it's available.
import()
const createCommandQueueModule = require('command-queue-module');
const myTrackingLibrary = createCommandQueueModule(['trackEvent'], (onLoad) => {
import('my-tracking-library').then(onLoad);
}));
// Works no matter if library is already loaded or not
myTrackingLibrary.trackEvent('Hello world');
<script>
tagconst createCommandQueueModule = require('command-queue-module');
const myTrackingLibrary = createCommandQueueModule(['trackEvent'], (onLoad) => {
const script = document.createElement('script');
script.src = 'https://example.org/my-tracking-library.umd.js';
script.onload = () => {
onLoad(window.MyTrackingLibrary)
};
document.body.append(script);
}));
// Works no matter if library is already loaded or not
myTrackingLibrary.trackEvent('Hello world');
FAQs
Create command queue proxies for modules
The npm package command-queue-module receives a total of 94 weekly downloads. As such, command-queue-module popularity was classified as not popular.
We found that command-queue-module 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.