@larcjs/core-lite
  Lightweight PAN messaging bus - Essential features only, 78% smaller than full version
LARC Core Lite provides the essential PAN (Page Area Network) messaging infrastructure for building loosely-coupled web applications. This is the lightweight version with routing and debugging features removed.
๐ฆ Bundle Size Comparison
| Package | Minified | Features | |---------|----------|----------| | @larcjs/core-lite | ~9KB | โ Pub/sub, retained messages, request/reply | | @larcjs/core | ~40KB | โ Everything + routing + debug + advanced features |
Use core-lite when:- โ You want the smallest possible bundle
- โ You only need pub/sub messaging
- โ You don't need dynamic routing
- โ You don't need advanced debugging
- ๐ง You need dynamic message routing
- ๐ง You need advanced debugging/tracing
- ๐ง You need rate limiting & security features
- ๐ง You want batteries-included
Features
- ๐ Zero build required โ Drop-in
element, communicate via CustomEvents - ๐ Loose coupling โ Components depend on topic contracts, not imports
- ๐ Framework friendly โ Works with React, Vue, Angular
- ๐ฌ Core messaging โ Pub/sub, request/reply, retained messages
- ๐ฏ Lightweight โ 9KB minified vs 40KB full version (78% reduction)
- โก Performance โ 300k+ messages/second, zero memory leaks
- ๐ Secure โ Zero dependencies, minimal attack surface
Installation
npm install @larcjs/core-lite
Quick Start
CDN Usage (No Build Required)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- Load the lite autoloader -->
<script type="module" src="https://unpkg.com/@larcjs/core-lite@latest/src/pan.js"></script>
</head>
<body>
<!-- The pan-bus is automatically created -->
<script>
// Publish a message
document.dispatchEvent(new CustomEvent('pan:publish', {
detail: {
topic: 'greeting.message',
payload: { text: 'Hello, PAN!' }
}
}));
// Subscribe to messages
document.addEventListener('pan:message', (e) => {
if (e.detail.topic === 'greeting.message') {
console.log('Received:', e.detail.payload.text);
}
});
</script>
</body>
</html>
Module Usage
import { PanBusLite } from '@larcjs/core-lite/pan-bus';
// The bus is automatically created by the autoloader
// Or create manually:
const bus = new PanBusLite();
document.body.appendChild(bus);
// Subscribe to a topic
bus.subscribe('user.login', (message) => {
console.log('User logged in:', message.payload);
});
// Publish a message
bus.publish('user.login', { userId: 123, name: 'Alice' });
Core Components
(Lite Version)
The lightweight message hub.
<pan-bus></pan-bus>
No configuration needed - it just works!
Simplifies publishing and subscribing.
<pan-client id="client"></pan-client>
<script>
const client = document.getElementById('client');
client.subscribe('data.changed', (msg) => {
console.log('Data updated:', msg.payload);
});
client.publish('data.request', { id: 42 });
</script>
Message Patterns
Publish/Subscribe
// Publisher
bus.publish('notifications.new', {
type: 'info',
message: 'Welcome!'
});
// Subscriber
bus.subscribe('notifications.new', (msg) => {
showNotification(msg.payload);
});
Request/Reply
// Responder
bus.subscribe('user.get', async (msg) => {
const user = await fetchUser(msg.payload.id);
return { ok: true, user };
});
// Requester
const result = await bus.request('user.get', { id: 123 });
if (result.ok) {
console.log('User:', result.user);
}
Retained Messages (State)
// Publish with retain flag
bus.publish('app.state', { theme: 'dark' }, { retain: true });
// Late subscribers immediately receive the retained message
bus.subscribe('app.state', (msg) => {
applyTheme(msg.payload.theme);
});
What's NOT Included (vs Full Version)
โ Dynamic Message Routing - Use @larcjs/core-routing if needed โ Debug/Tracing Tools - Use @larcjs/core-debug if needed โ Rate Limiting - Not available in lite โ Message Size Validation - Not available in lite โ Statistics Tracking - Not available in lite โ LRU Cache Eviction - Simple Map instead
These features add 31KB to the bundle. If you need them, use @larcjs/core instead.
Upgrading to Full Version
Need more features? Switch to the full version:
npm uninstall @larcjs/core-lite
npm install @larcjs/core
Or add routing/debug separately:
npm install @larcjs/core-routing @larcjs/core-debug
Performance
- Throughput: 300,000+ messages/second
- Latency: <1ms per message (local)
- Memory: Zero leaks, constant memory usage
- Bundle size: 9KB minified
pan.min.mjs: 3.6KB (autoloader)
- pan-bus.min.mjs: 3.0KB (lite bus)
- pan-client.min.mjs: 2.0KB (client API)
Browser Support
- โ Chrome/Edge 90+
- โ Firefox 88+
- โ Safari 14+
- โ Opera 76+
Related Packages
- @larcjs/core โ Full-featured version (40KB with routing/debug)
- @larcjs/core-routing โ Dynamic routing add-on (8KB)
- @larcjs/core-debug โ Debug tools add-on (3KB)
- @larcjs/ui โ UI components built on PAN
- @larcjs/core-types โ TypeScript type definitions
Documentation
Contributing
Contributions are welcome! Please see our Contributing Guide.
License
MIT ยฉ Chris Robison
Support
- ๐ Documentation
- ๐ฌ Discussions
- ๐ Issue Tracker