Home / packages / core-lite / README

@larcjs/core-lite

![Version](https://www.npmjs.com/package/@larcjs/core-lite) ![License](LICENSE) ![Bundle Size](#)
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
Use full @larcjs/core when:
  • ๐Ÿ”ง 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

Documentation

Contributing

Contributions are welcome! Please see our Contributing Guide.

License

MIT ยฉ Chris Robison

Support